Exemple #1
0
 def add_inputs(self, inputs):
     aux = []
     count_good = 0
     count_bad = 0
     if isinstance(inputs, type({})):
         aux = [inputs["packet"]]
     elif isinstance(inputs, type([])):
         aux = map(lambda x: x["packet"], inputs)
     else:
         utils.crash("Unknown inputs provided: %s" % inputs)
     inputs = aux
     for p in inputs:
         if self.filter_src_mac:  # sanity checks on the input packets
             macs = self.state.model.getClientMacAddresses()
             if p["src"] not in macs or p["dst"] not in macs or p[
                     "src"] != self.mymac or p["src"] == p["dst"]:
                 count_bad += 1
                 continue
         ep = ethernet.ethernet("se.packet%d" % self.input_counter)
         ep.src = MacAddress(p["src"])
         ep.dst = MacAddress(p["dst"])
         ep.parsed = p["parsed"]
         ep.next = p["next"]
         ep.type = p["type"]
         ep.arr = p["arr"]
         self.input_counter += 1
         count_good += 1
         self.pkts[ep.name] = ep
         self.enableAction("send_packet", ep.name)
     self.log.info("Accepted %d new packets, discarded %d invalid packets" %
                   (count_good, count_bad))
Exemple #2
0
    def fire_send_fv_packets(self):

        time_val = time() * 1000
        logger.info("Sending FV Packets rate: " + str(self.sg.fv_pkt_rate) + " with vlan: " + str(self.sg.VLAN_ID) + " packets: " + str(len(self.sg.packets)))

        for pkt in self.sg.packets:
            logger.info("Packet:")
            packet = ethernet()
            packet.src = '\x00' + struct.pack('!Q',pkt[0])[3:8]
            packet.dst = NDP_MULTICAST

            payload = struct.pack('QHQHq',pkt[0],pkt[1],pkt[2],pkt[3],time_val)

            if(self.sg.VLAN_ID != None and self.sg.VLAN_ID != 65535):
                vlan_packet = vlan()
                vlan_packet.id = self.sg.VLAN_ID
                vlan_packet.c = 0
                vlan_packet.pcp = 0
                vlan_packet.eth_type = 0x88b6
                vlan_packet.set_payload(payload)

                packet.set_payload(vlan_packet)
                packet.type = ethernet.VLAN_TYPE

            else:
                packet.set_payload(payload)
                packet.type = 0x88b6

            inst.send_openflow_packet(pkt[0], packet.tostring(), int(pkt[1]))

        self.post_callback(fv_pkt_rate, self.fire_send_fv_packets)
def create_discovery_packet(dpid, portno, ttl_):    

    # Create lldp packet
    discovery_packet = lldp()
    cid = chassis_id()

    # nbo 
    cid.fill(chassis_id.SUB_LOCAL, array.array('B', 'dpid:' + hex(long(dpid))[2:-1]))
    discovery_packet.add_tlv(cid)

    pid = port_id()
    pid.fill(2,array.array('B',struct.pack('!H', portno)))
    discovery_packet.add_tlv(pid)

    ttlv = ttl()
    ttlv.fill(ttl_)
    discovery_packet.add_tlv(ttlv)

    discovery_packet.add_tlv(end_tlv())

    eth = ethernet()
    # To insure that the LLDP src mac address is not a multicast
    # address, since we have no control on choice of dpid
    eth.src = '\x00' + struct.pack('!Q',dpid)[3:8]
    eth.dst = NDP_MULTICAST
    eth.set_payload(discovery_packet)
    eth.type = ethernet.LLDP_TYPE

    return eth
Exemple #4
0
    def send_traceroute_packet(self,dpid,my_vlan,out_port,data):
        #build ethernet packet
        packet = ethernet()
        packet.src = '\x00' + struct.pack('!Q',dpid)[3:8]
        packet.dst = TRACEROUTE_MAC
        #pack circuit_id into payload
        payload = struct.pack('I',data)
        
        if(my_vlan != None and my_vlan != 65535):
            vlan_packet = vlan()
            vlan_packet.id = my_vlan
            vlan_packet.c = 0
            vlan_packet.pcp = 0
            vlan_packet.eth_type = 0x88b5
            vlan_packet.set_payload(payload)

            packet.set_payload(vlan_packet)
            packet.type = ethernet.VLAN_TYPE
            
        else:
            packet.set_payload(payload)
            packet.type = 0x88b5
        
        inst.send_openflow_packet(int(dpid), packet.tostring(),int(out_port))

        return
Exemple #5
0
def create_discovery_packet(dpid, portno, ttl_):

    # Create lldp packet
    discovery_packet = lldp()
    cid = chassis_id()

    # nbo
    cid.fill(4, array.array('B', struct.pack('!Q', dpid))[2:8])
    discovery_packet.add_tlv(cid)

    pid = port_id()
    pid.fill(2, array.array('B', struct.pack('!H', portno)))
    discovery_packet.add_tlv(pid)

    ttlv = ttl()
    ttlv.fill(ttl_)
    discovery_packet.add_tlv(ttlv)

    discovery_packet.add_tlv(end_tlv())

    eth = ethernet()
    # To insure that the LLDP src mac address is not a multicast
    # address, since we have no control on choice of dpid
    eth.src = '\x00' + struct.pack('!Q', dpid)[3:8]
    eth.dst = NDP_MULTICAST
    eth.set_payload(discovery_packet)
    eth.type = ethernet.LLDP_TYPE

    return eth
Exemple #6
0
    def fire_send_fv_packets(self):

        time_val = time.time() * 1000
        logger.info("Sending FV Packets rate: " + str(self.fv_pkt_rate) +
                    " with vlan: " + str(self.FV_VLAN_ID) + " packets: " +
                    str(len(self.packets)))

        for pkt in self.packets:
            logger.info("Packet:")
            packet = ethernet()
            packet.src = '\x00' + struct.pack('!Q', pkt[0])[3:8]
            packet.dst = NDP_MULTICAST

            payload = struct.pack('QHQHq', pkt[0], pkt[1], pkt[2], pkt[3],
                                  time_val)

            if (self.FV_VLAN_ID != None and self.FV_VLAN_ID != 65535):
                vlan_packet = vlan()
                vlan_packet.id = self.FV_VLAN_ID
                vlan_packet.c = 0
                vlan_packet.pcp = 0
                vlan_packet.eth_type = 0x88b6
                vlan_packet.set_payload(payload)

                packet.set_payload(vlan_packet)
                packet.type = ethernet.VLAN_TYPE

            else:
                packet.set_payload(payload)
                packet.type = 0x88b6

            Component.send_openflow_packet(pkt[0], packet.tostring(),
                                           int(pkt[1]))

        self.post_callback(fv_pkt_rate_interval, self.fire_send_fv_packets)
Exemple #7
0
    def send_traceroute_packet(self, dpid, my_vlan, out_port, data):
        #build ethernet packet
        packet = ethernet()
        packet.src = '\x00' + struct.pack('!Q', dpid)[3:8]
        packet.dst = TRACEROUTE_MAC
        #pack circuit_id into payload
        payload = struct.pack('I', data)

        if (my_vlan != None and my_vlan != 65535):
            vlan_packet = vlan()
            vlan_packet.id = my_vlan
            vlan_packet.c = 0
            vlan_packet.pcp = 0
            vlan_packet.eth_type = 0x88b5
            vlan_packet.set_payload(payload)

            packet.set_payload(vlan_packet)
            packet.type = ethernet.VLAN_TYPE

        else:
            packet.set_payload(payload)
            packet.type = 0x88b5

        inst.send_openflow_packet(int(dpid), packet.tostring(), int(out_port))

        return
Exemple #8
0
    def send_traceroute_packet(self, **kwargs):
        logger.debug("Sending pack to trigger process_trace_packet.")

        dpid     = kwargs.get('dpid')
        my_vlan  = kwargs.get('my_vlan')
        out_port = kwargs.get('out_port')
        data     = kwargs.get('data')

        #build ethernet packet
        packet = ethernet()
        packet.src = '\x00' + struct.pack('!Q',dpid)[3:8]
        packet.dst = TRACEROUTE_MAC
        #pack circuit_id into payload
        payload = struct.pack('I',data)
        
        if(my_vlan != None and my_vlan != 65535):
            vlan_packet = vlan()
            vlan_packet.id = my_vlan
            vlan_packet.c = 0
            vlan_packet.pcp = 0
            vlan_packet.eth_type = 0x88b5
            vlan_packet.set_payload(payload)

            packet.set_payload(vlan_packet)
            packet.type = ethernet.VLAN_TYPE
            
        else:
            packet.set_payload(payload)
            packet.type = 0x88b5
        
        Component.send_openflow_packet(self, int(dpid), packet.tostring(),int(out_port))

        return
Exemple #9
0
    def send_traceroute_packet(self, **kwargs):
        logger.debug("Sending pack to trigger process_trace_packet.")

        dpid = kwargs.get('dpid')
        my_vlan = kwargs.get('my_vlan')
        out_port = kwargs.get('out_port')
        data = kwargs.get('data')

        #build ethernet packet
        packet = ethernet()
        packet.src = '\x00' + struct.pack('!Q', dpid)[3:8]
        packet.dst = TRACEROUTE_MAC
        #pack circuit_id into payload
        payload = struct.pack('I', data)

        if (my_vlan != None and my_vlan != 65535):
            vlan_packet = vlan()
            vlan_packet.id = my_vlan
            vlan_packet.c = 0
            vlan_packet.pcp = 0
            vlan_packet.eth_type = 0x88b5
            vlan_packet.set_payload(payload)

            packet.set_payload(vlan_packet)
            packet.type = ethernet.VLAN_TYPE

        else:
            packet.set_payload(payload)
            packet.type = 0x88b5

        Component.send_openflow_packet(self, int(dpid), packet.tostring(),
                                       int(out_port))

        return
Exemple #10
0
 def build_ethernet_packet(self, name, dst, payload, type):
     eth = ethernet.ethernet(name)
     eth.packet_id = self.genPacketID()
     eth.set_payload(payload)
     if type != 0:
         eth.type = type
     eth.src = self.mymac.copy()
     eth.dst = dst.copy()
     return eth
Exemple #11
0
 def build_ethernet_packet(self, name, dst, payload, type):
     eth = ethernet.ethernet(name)
     eth.packet_id = self.genPacketID()
     eth.set_payload(payload)
     if type != 0:
         eth.type = type
     eth.src = self.mymac.copy()
     eth.dst = dst.copy()
     return eth
Exemple #12
0
    def f(event):
        if event.reason == openflow.OFPR_NO_MATCH:
            reason = openflow.OFPR_NO_MATCH
        elif event.reason == openflow.OFPR_ACTION:
            reason = openflow.OFPR_ACTION
        else:
            print 'packet_in reason type %u unknown...just passing along' % event.reason
            reason = event.reason

        if event.buffer_id == UINT32_MAX:
            buffer_id = None
        else:
            buffer_id = event.buffer_id

        try:
            packet = ethernet(array.array('B', event.buf))
        except IncompletePacket, e:
            log.err('Incomplete Ethernet header', system='pyapi')
Exemple #13
0
    def f(event):
        if event.reason == openflow.OFPR_NO_MATCH:
            reason = openflow.OFPR_NO_MATCH
        elif event.reason == openflow.OFPR_ACTION:
            reason = openflow.OFPR_ACTION
        else:
            lg.warning('packet_in reason type %u unknown...just passing along' % event.reason)
            reason = event.reason

        if event.buffer_id == UINT32_MAX:
            buffer_id = None
        else:
            buffer_id = event.buffer_id

        try:
            packet = ethernet(array.array('B', event.buf))
        except IncompletePacket, e:
            lg.error('Incomplete Ethernet header')
Exemple #14
0
    def f(event):
        if event.reason == openflow.OFPR_NO_MATCH:
            reason = openflow.OFPR_NO_MATCH
        elif event.reason == openflow.OFPR_ACTION:
            reason = openflow.OFPR_ACTION
        else:
            print "packet_in reason type %u unknown...just passing along" % event.reason
            reason = event.reason

        if event.buffer_id == UINT32_MAX:
            buffer_id = None
        else:
            buffer_id = event.buffer_id

        try:
            packet = ethernet(array.array("B", event.buf))
        except IncompletePacket, e:
            log.err("Incomplete Ethernet header", system="pyapi")
Exemple #15
0
def create_discovery_packet(dpid, portno, vlan_id, ttl_):    

    # Create lldp packet
    discovery_packet = lldp()
    cid = chassis_id()

    # nbo 
    cid.fill(chassis_id.SUB_LOCAL, array.array('B', 'dpid:' + hex(long(dpid))[2:-1]))
    discovery_packet.add_tlv(cid)

    pid = port_id()
    pid.fill(2,array.array('B',struct.pack('!H', portno)))
    discovery_packet.add_tlv(pid)

    ttlv = ttl()
    ttlv.fill(ttl_)
    discovery_packet.add_tlv(ttlv)

    discovery_packet.add_tlv(end_tlv())

    eth = ethernet()
    eth.src = '\x00' + struct.pack('!Q',dpid)[3:8]
    eth.dst = NDP_MULTICAST
    
    if(vlan_id != None):
        
        vlan_packet = vlan()
        vlan_packet.id = vlan_id
        vlan_packet.pcp = 0
        vlan_packet.c = 0
        vlan_packet.eth_type = ethernet.LLDP_TYPE
        vlan_packet.set_payload(discovery_packet)

        eth.set_payload(vlan_packet)
        eth.type = ethernet.VLAN_TYPE
        eth.eth_type = ethernet.LLDP_TYPE
    
    else:
        eth.set_payload(discovery_packet)
        eth.type = ethernet.LLDP_TYPE
        

    return eth
Exemple #16
0
def create_arp_request(srcMAC, srcIP, dstIP):
    arpRequest = arp()
    arpRequest.hwdst = ETHER_ANY
    #    arpRequest.hwdst = ETHER_BROADCAST
    arpRequest.protodst = dstIP
    arpRequest.hwsrc = srcMAC
    arpRequest.protosrc = srcIP
    arpRequest.hwtype = arpRequest.HW_TYPE_ETHERNET
    arpRequest.hwlen = 6
    arpRequest.protolen = 4
    arpRequest.opcode = arpRequest.REQUEST

    ethRequest = ethernet()
    ethRequest.dst = ETHER_BROADCAST
    ethRequest.src = srcMAC
    ethRequest.type = ethernet.ARP_TYPE
    ethRequest.set_payload(arpRequest)

    return ethRequest.tostring()
Exemple #17
0
def create_arp_request(srcMAC, srcIP, dstIP):
    arpRequest = arp()
    arpRequest.hwdst = ETHER_ANY
#    arpRequest.hwdst = ETHER_BROADCAST
    arpRequest.protodst = dstIP
    arpRequest.hwsrc = srcMAC
    arpRequest.protosrc = srcIP
    arpRequest.hwtype = arpRequest.HW_TYPE_ETHERNET
    arpRequest.hwlen = 6
    arpRequest.protolen = 4
    arpRequest.opcode = arpRequest.REQUEST

    ethRequest = ethernet()
    ethRequest.dst = ETHER_BROADCAST
    ethRequest.src = srcMAC
    ethRequest.type = ethernet.ARP_TYPE
    ethRequest.set_payload(arpRequest)

    return ethRequest.tostring()
Exemple #18
0
def create_virtual_arp_response(packet, srcMAC, srcIP):
    arpReqHeader = packet.find('arp')

    arpResponse = arp()
    arpResponse.hwdst = arpReqHeader.hwsrc
    arpResponse.protodst = arpReqHeader.protosrc
    arpResponse.hwsrc = srcMAC
    arpResponse.protosrc = srcIP
    arpResponse.hwtype = arpReqHeader.HW_TYPE_ETHERNET
    arpResponse.hwlen = 6
    arpResponse.prototype = arpResponse.PROTO_TYPE_IP
    arpResponse.protolen = 4
    arpResponse.opcode = arpResponse.REPLY

    ethResponse = ethernet()
    ethResponse.dst = packet.src
    ethResponse.src = srcMAC
    ethResponse.type = ethernet.ARP_TYPE
    ethResponse.set_payload(arpResponse)

    return ethResponse.tostring()
Exemple #19
0
def create_virtual_arp_response(packet, srcMAC, srcIP):
    arpReqHeader = packet.find('arp')

    arpResponse = arp()
    arpResponse.hwdst = arpReqHeader.hwsrc
    arpResponse.protodst = arpReqHeader.protosrc
    arpResponse.hwsrc = srcMAC
    arpResponse.protosrc = srcIP
    arpResponse.hwtype = arpReqHeader.HW_TYPE_ETHERNET
    arpResponse.hwlen = 6
    arpResponse.prototype = arpResponse.PROTO_TYPE_IP
    arpResponse.protolen = 4
    arpResponse.opcode = arpResponse.REPLY

    ethResponse = ethernet()
    ethResponse.dst = packet.src
    ethResponse.src = srcMAC
    ethResponse.type = ethernet.ARP_TYPE
    ethResponse.set_payload(arpResponse)

    return ethResponse.tostring()
Exemple #20
0
def create_discovery_packet(dpid, hwaddr, portno, ttl_):

    # Create lldp packet
    discovery_packet = lldp()
    cid = chassis_id()

    # nbo
    cid.fill(chassis_id.SUB_NETWORK, array.array('B', struct.pack('!Q', dpid)))
    discovery_packet.add_tlv(cid)

    pid = port_id()
    pid.fill(2, array.array('B', struct.pack('!H', portno)))
    discovery_packet.add_tlv(pid)

    ttlv = ttl()
    ttlv.fill(ttl_)
    discovery_packet.add_tlv(ttlv)

    discovery_packet.add_tlv(end_tlv())

    eth = ethernet()

    # Ideally, LLDPs sent out of a port shud have its hwaddr. But,
    # if the switch is reporting MAC address same as DPID, then we
    # shud distinguish from it using local MAC addr. This also
    # insures that the LLDP src mac addr is not a multicast addr.
    if hwaddr == struct.pack('!Q', dpid)[2:8]:
        eth.src = struct.pack('!Q', dpid | 0x020000000000)[2:8]
    else:
        eth.src = hwaddr

    eth.dst = NDP_MULTICAST
    eth.set_payload(discovery_packet)
    eth.type = ethernet.LLDP_TYPE

    return eth
Exemple #21
0
def create_discovery_packet(dpid, hwaddr, portno, ttl_):

    # Create lldp packet
    discovery_packet = lldp()
    cid = chassis_id()

    # nbo 
    cid.fill(chassis_id.SUB_NETWORK, array.array('B', struct.pack('!Q',dpid)))
    discovery_packet.add_tlv(cid)

    pid = port_id()
    pid.fill(2,array.array('B',struct.pack('!H', portno)))
    discovery_packet.add_tlv(pid)

    ttlv = ttl()
    ttlv.fill(ttl_)
    discovery_packet.add_tlv(ttlv)

    discovery_packet.add_tlv(end_tlv())

    eth = ethernet()

    # Ideally, LLDPs sent out of a port shud have its hwaddr. But,
    # if the switch is reporting MAC address same as DPID, then we
    # shud distinguish from it using local MAC addr. This also
    # insures that the LLDP src mac addr is not a multicast addr.
    if hwaddr == struct.pack('!Q',dpid)[2:8]:
        eth.src = struct.pack('!Q', dpid | 0x020000000000)[2:8]
    else:
        eth.src = hwaddr

    eth.dst = NDP_MULTICAST
    eth.set_payload(discovery_packet)
    eth.type = ethernet.LLDP_TYPE

    return eth
Exemple #22
0
 def enqueueQueryToController(self, dp_id, buffer_id, packet, inport,
                              reason, max_length):
     if max_length == 0:
         packet = ethernet()
     self.state.model.controller.enqueueQuery(dp_id, buffer_id, packet,
                                              inport, reason)
Exemple #23
0
exec("obj = " + class_name + "(None,None)")

conn = MySQLdb.connect('localhost', 'nox_dwh', 'nox_dwh', 'nox_dwh')
cursor = conn.cursor()

cursor.execute(
    "SELECT ID, CREATED_DT, DP_ID, PORT_ID, REASON, BUFFER, TOTAL_LEN FROM FLOW_SETUP ORDER BY ID"
)
#cursor.execute ("SELECT ID, CREATED_DT, DP_ID, PORT_ID, REASON, BUFFER, TOTAL_LEN FROM FLOW_SETUP ORDER BY ID LIMIT 10000")
rows = cursor.fetchall()
for row in rows:

    id = row[0]
    created_dt = row[1]
    dp_id = row[2]
    port_id = row[3]
    reason = row[4]
    buffer = row[5]
    total_len = row[6]
    packet = ethernet(array.array('B', buffer))

    obj.packet_in_callback(dp_id, port_id, reason, total_len, id, packet,
                           created_dt)

print "Number of rows returned: %d" % cursor.rowcount

cursor.close()
conn.close()

obj.timer_callback(0)
Exemple #24
0
def createTestPacketIn():
    eth = ethernet.ethernet("test_in")
    eth.packet_id = 0
    eth.type = 0x05ff
    eth.src = "88:88:88:88:88:88"
    return eth
Exemple #25
0
def createBarrierPacket():
    eth = ethernet.ethernet("barrier_test")
    eth.packet_id = 0
    eth.type = 0x05ff
    eth.src = "66:66:66:66:66:66"
    return eth
Exemple #26
0
def createTestPacket():
    eth = ethernet.ethernet("test")
    eth.packet_id = 0
    eth.type = 0x05ff
    eth.src = "55:55:55:55:55:55"
    return eth
Exemple #27
0
    def handle_flow_in(self, event):

        if not event.active:
            return CONTINUE
        indatapath = netinet.create_datapathid_from_host(event.datapath_id)
        route = pyrouting.Route()

        sloc = event.route_source
        if sloc == None:
            sloc = event.src_location['sw']['dp']
            route.id.src = netinet.create_datapathid_from_host(sloc)
            inport = event.src_location['port']
            sloc = sloc | (inport << 48)
        else:
            route.id.src = netinet.create_datapathid_from_host(sloc & DP_MASK)
            inport = (sloc >> 48) & PORT_MASK
        if len(event.route_destinations) > 0:
            dstlist = event.route_destinations
        else:
            dstlist = event.dst_locations

        checked = False
        for dst in dstlist:
            if isinstance(dst, dict):
                if not dst['allowed']:
                    continue
                dloc = dst['authed_location']['sw']['dp']
                route.id.dst = netinet.create_datapathid_from_host(dloc
                                                                   & DP_MASK)
                outport = dst['authed_location']['port']
                dloc = dloc | (outport << 48)
            else:
                dloc = dst
                route.id.dst = netinet.create_datapathid_from_host(dloc
                                                                   & DP_MASK)
                outport = (dloc >> 48) & PORT_MASK
            if dloc == 0:
                continue
            if self.routing.get_route(route):
                checked = True
                if self.routing.check_route(route, inport, outport):
                    log.debug('Found route %s.' % hex(route.id.src.as_host())+\
                            ':'+str(inport)+' to '+hex(route.id.dst.as_host())+\
                            ':'+str(outport))
                    if route.id.src == route.id.dst:
                        firstoutport = outport
                    else:
                        firstoutport = route.path[0].outport

                    p = []
                    if route.id.src == route.id.dst:
                        p.append(str(inport))
                        p.append(str(indatapath))
                        p.append(str(firstoutport))
                    else:
                        s2s_links = len(route.path)
                        p.append(str(inport))
                        p.append(str(indatapath))
                        for i in range(0, s2s_links):
                            p.append(str(route.path[i].dst))
                        p.append(str(outport))

                    #print 'unicast'
                    #print type(event.flow)
                    #print dir(event.flow)
                    #print str(event.flow)#.to_string()

                    self.routing.setup_route(event.flow, route, inport, \
                                    outport, FLOW_TIMEOUT, [], True)

                    # Send Barriers
                    pending_route = []
                    #log.debug("Sending BARRIER to switches:")
                    # Add barrier xids
                    for dpid in p[1:len(p) - 1]:
                        log.debug("Sending barrier to %s", dpid)
                        pending_route.append(self.send_barrier(int(dpid, 16)))
                    # Add packetout info
                    pending_route.append([indatapath, inport, event])
                    # Store new pending_route (waiting for barrier replies)
                    self.pending_routes.append(pending_route)

                    # send path to be highlighted to GUI
                    #self.send_to_gui("highlight",p)

                    # Send packet out (do it after receiving barrier(s))
                    if indatapath == route.id.src or \
                        pyrouting.dp_on_route(indatapath, route):
                        #pass
                        self.routing.send_packet(indatapath, inport, \
                            openflow.OFPP_TABLE,event.buffer_id,event.buf,"", \
                            False, event.flow)
                    else:
                        log.debug("Packet not on route - dropping.")
                    return CONTINUE
                else:
                    log.debug("Invalid route between %s." \
                        % hex(route.id.src.as_host())+':'+str(inport)+' to '+\
                        hex(route.id.dst.as_host())+':'+str(outport))
            else:
                log.debug("No route between %s and %s." % \
                    (hex(route.id.src.as_host()), hex(route.id.dst.as_host())))
        if not checked:
            #just broadcast to external port
            #black food
            eth = ethernet(event.buf)
            if eth.type != ethernet.IP_TYPE and\
                eth.type != ethernet.ARP_TYPE and\
                eth.type != ethernet.PAE_TYPE and\
                eth.type != ethernet.VLAN_TYPE:
                return CONTINUE
            for d in self.dp_stats:
                for port in self.dp_stats[d]['ports']:
                    if not self.pytop.is_internal(\
                    netinet.create_datapathid_from_host(d),port):
                        self.send_openflow_packet(d, event.buf, port)
            return STOP

            if event.flow.dl_dst.is_broadcast():
                log.debug("Setting up FLOOD flow on %s", str(indatapath))
                self.routing.setup_flow(event.flow, indatapath, \
                    openflow.OFPP_FLOOD, event.buffer_id, event.buf, \
                        BROADCAST_TIMEOUT, "", \
                        event.flow.dl_type == htons(ethernet.IP_TYPE))
            else:
                inport = ntohs(event.flow.in_port)
                log.debug("Flooding")
                #print 'flooding '
                self.routing.send_packet(indatapath, inport, \
                    openflow.OFPP_FLOOD, \
                    event.buffer_id, event.buf, "", \
                    event.flow.dl_type == htons(ethernet.IP_TYPE),\
                    event.flow)
        else:
            log.debug("Dropping packet")

        return STOP
Exemple #28
0
 def enqueueQueryToController(self, dp_id, buffer_id, packet, inport, reason, max_length):
     if max_length == 0:
         packet = ethernet()
     self.state.model.controller.enqueueQuery(dp_id, buffer_id, packet, inport, reason)
Exemple #29
0
    def handle_flow_in(self, event):
    
        if not event.active:
            return CONTINUE
        indatapath = netinet.create_datapathid_from_host(event.datapath_id)
        route = pyrouting.Route()
        
        sloc = event.route_source
        if sloc == None:
            sloc = event.src_location['sw']['dp']
            route.id.src = netinet.create_datapathid_from_host(sloc)
            inport = event.src_location['port']
            sloc = sloc | (inport << 48)
        else:
            route.id.src = netinet.create_datapathid_from_host(sloc & DP_MASK)
            inport = (sloc >> 48) & PORT_MASK
        if len(event.route_destinations) > 0:
            dstlist = event.route_destinations
        else:
            dstlist = event.dst_locations
        
        checked = False
        for dst in dstlist:
            if isinstance(dst, dict):
                if not dst['allowed']:
                    continue
                dloc = dst['authed_location']['sw']['dp']
                route.id.dst = netinet.create_datapathid_from_host(dloc & DP_MASK)
                outport = dst['authed_location']['port']
                dloc = dloc | (outport << 48)
            else:
                dloc = dst
                route.id.dst = netinet.create_datapathid_from_host(dloc & DP_MASK)
                outport = (dloc >> 48) & PORT_MASK
            if dloc == 0:
                continue
            if self.routing.get_route(route):
                checked = True
                if self.routing.check_route(route, inport, outport):
                    log.debug('Found route %s.' % hex(route.id.src.as_host())+\
                            ':'+str(inport)+' to '+hex(route.id.dst.as_host())+\
                            ':'+str(outport))
                    if route.id.src == route.id.dst:
                        firstoutport = outport
                    else:
                        firstoutport = route.path[0].outport
                    
                    p = []
                    if route.id.src == route.id.dst:
                        p.append(str(inport))
                        p.append(str(indatapath))
                        p.append(str(firstoutport))
                    else:
                        s2s_links = len(route.path)
                        p.append(str(inport))
                        p.append(str(indatapath))
                        for i in range(0,s2s_links):
                            p.append(str(route.path[i].dst))
                        p.append(str(outport))

                    #print 'unicast'
                    #print type(event.flow)
                    #print dir(event.flow)
                    #print str(event.flow)#.to_string()
                            
                    self.routing.setup_route(event.flow, route, inport, \
                                    outport, FLOW_TIMEOUT, [], True)
                                    
                    # Send Barriers                
                    pending_route = []
                    #log.debug("Sending BARRIER to switches:")
                    # Add barrier xids
                    for dpid in p[1:len(p)-1]:
                        log.debug("Sending barrier to %s", dpid)
                        pending_route.append(self.send_barrier(int(dpid,16)))
                    # Add packetout info
                    pending_route.append([indatapath, inport, event])
                    # Store new pending_route (waiting for barrier replies)
                    self.pending_routes.append(pending_route)
                           
                    # send path to be highlighted to GUI
                    #self.send_to_gui("highlight",p)
                    
                    # Send packet out (do it after receiving barrier(s))
                    if indatapath == route.id.src or \
                        pyrouting.dp_on_route(indatapath, route):
                        #pass
                        self.routing.send_packet(indatapath, inport, \
                            openflow.OFPP_TABLE,event.buffer_id,event.buf,"", \
                            False, event.flow)
                    else:
                        log.debug("Packet not on route - dropping.")
                    return CONTINUE
                else:
                    log.debug("Invalid route between %s." \
                        % hex(route.id.src.as_host())+':'+str(inport)+' to '+\
                        hex(route.id.dst.as_host())+':'+str(outport))
            else:
                log.debug("No route between %s and %s." % \
                    (hex(route.id.src.as_host()), hex(route.id.dst.as_host())))
        if not checked:
            #just broadcast to external port
            #black food
            eth = ethernet(event.buf)
            if eth.type != ethernet.IP_TYPE and\
                eth.type != ethernet.ARP_TYPE and\
                eth.type != ethernet.PAE_TYPE and\
                eth.type != ethernet.VLAN_TYPE:
                return CONTINUE
            for d in self.dp_stats:
                for port in self.dp_stats[d]['ports']:
                    if not self.pytop.is_internal(\
                    netinet.create_datapathid_from_host(d),port):
                        self.send_openflow_packet(d,event.buf,port)
            return STOP

            

            if event.flow.dl_dst.is_broadcast():
                log.debug("Setting up FLOOD flow on %s", str(indatapath))
                self.routing.setup_flow(event.flow, indatapath, \
                    openflow.OFPP_FLOOD, event.buffer_id, event.buf, \
                        BROADCAST_TIMEOUT, "", \
                        event.flow.dl_type == htons(ethernet.IP_TYPE))
            else:
                inport = ntohs(event.flow.in_port)
                log.debug("Flooding")
                #print 'flooding '
                self.routing.send_packet(indatapath, inport, \
                    openflow.OFPP_FLOOD, \
                    event.buffer_id, event.buf, "", \
                    event.flow.dl_type == htons(ethernet.IP_TYPE),\
                    event.flow)
        else:
            log.debug("Dropping packet")

        return STOP
Exemple #30
0
def newEthernetPacket(name):
    from nox.lib.packet.ethernet import ethernet
    if name not in symbolic_packets.keys():
        symbolic_packets[name] = ethernet(name)
    return symbolic_packets[name]
Exemple #31
0
def newEthernetPacket(name):
    from nox.lib.packet.ethernet import ethernet
    if name not in symbolic_packets.keys():
        symbolic_packets[name] = ethernet(name)
    return symbolic_packets[name]
Exemple #32
0
exec("obj = " + class_name + "(None,None)") 

conn = MySQLdb.connect ('localhost','nox_dwh','nox_dwh', 'nox_dwh')
cursor = conn.cursor() 

cursor.execute ("SELECT ID, CREATED_DT, DP_ID, PORT_ID, REASON, BUFFER, TOTAL_LEN FROM FLOW_SETUP ORDER BY ID")
#cursor.execute ("SELECT ID, CREATED_DT, DP_ID, PORT_ID, REASON, BUFFER, TOTAL_LEN FROM FLOW_SETUP ORDER BY ID LIMIT 10000")
rows = cursor.fetchall ()
for row in rows:

  id = row[0] 
  created_dt = row[1]
  dp_id = row[2] 
  port_id = row[3]
  reason = row[4]
  buffer = row[5]
  total_len = row[6] 
  packet = ethernet(array.array('B', buffer))

  obj.packet_in_callback(dp_id, port_id, reason, total_len, id, packet, created_dt)

print "Number of rows returned: %d" % cursor.rowcount

cursor.close()
conn.close()



obj.timer_callback(0)