Exemplo n.º 1
0
    def _packet_in_handler(self, ev):
        self.logger.debug("my_arp: _packet_in_handler:")
        # If you hit this you might want to increase
        # the "miss_send_length" of your switch
        if ev.msg.msg_len < ev.msg.total_len:
            self.logger.debug("packet truncated: only %s of %s bytes",
                              ev.msg.msg_len, ev.msg.total_len)
        msg = ev.msg
        datapath = msg.datapath
        # ofproto = datapath.ofproto
        inPort = msg.match['in_port']
        packets = Packet(msg.data)
        dpid = datapath.id
        self.mac_to_port.setdefault(dpid, {})
        eth = packets.get_protocols(ethernet)[0]
        src = eth.src
        self.mac_to_port[dpid][src] = inPort
        data = msg.data

        # print "packets: ", packets
        # print "packets.get_protocols(ethernet): ", packets.get_protocols(ethernet)
        if etherFrame.ethertype == ether.ETH_TYPE_ARP:
            # print "packets: ", packets
            # print "packets.get_protocols(ethernet): ", packets.get_protocols(ethernet)
            self.receive_arp(datapath, packets, etherFrame, inPort, data)
            return 0
        else:
            self.logger.debug("Drop packet")
            return 1
Exemplo n.º 2
0
    def _packet_in_handler(self, ev):
        self.logger.debug("my_arp: _packet_in_handler:")
        # If you hit this you might want to increase
        # the "miss_send_length" of your switch
        if ev.msg.msg_len < ev.msg.total_len:
            self.logger.debug("packet truncated: only %s of %s bytes",
                              ev.msg.msg_len, ev.msg.total_len)
        msg = ev.msg
        datapath = msg.datapath
        # ofproto = datapath.ofproto
        inPort = msg.match['in_port']
        packets = Packet(msg.data)
        dpid = datapath.id
        self.mac_to_port.setdefault(dpid, {})

        eth = packets.get_protocols(ethernet)[0]
        src = eth.src
        dst = eth.dst
        self.mac_to_port[dpid][src] = inPort
        data = msg.data

        self.arp_learning.setdefault(dpid, [])
        self.packetToport.setdefault(dpid, [])

        etherFrame = packets.get_protocol(ethernet)
        # if dst == LLDP_MAC_NEAREST_BRIDGE:
        #     return
        # print "packets: ", packets
        # print "packets.get_protocols(ethernet): ", packets.get_protocols(ethernet)

        # print "etherFrame######", etherFrame
        # etherFrame = packets.get_protocol(ethernet)
        etherFrame = packets.get_protocol(ethernet)
        # print etherFrame
        # print ether
        # print hex(etherFrame.ethertype)
        # print hex(ether.ETH_TYPE_ARP)
        if etherFrame.ethertype == ether.ETH_TYPE_ARP:
            arpPacket = packets.get_protocol(arp)
            arpArriveTime = time.time()
            srcMac = etherFrame.src
            arp_dstIP = arpPacket.dst_ip
            self.packetToport[datapath.id] = [srcMac, arp_dstIP, inPort, arpArriveTime]
            # print "arp"
            # print "packets: ", packets
            # print "packets.get_protocols(ethernet): ", packets.get_protocols(ethernet)
            # print "ARP: %s" % arpPacket.opcode
            # # self.logger.info("packet in %s %s %s %s", dpid, src, dst, in_port)
            # if arpPacket.opcode == 1:
            #     print "ARP Requst"
            #     self.logger.info("packet in %s %s %s %s", datapath.id, srcMac, dst, inPort)
            # elif arpPacket.opcode == 2:
            #     print "ARP Reply"
            #     self.logger.info("packet in %s %s %s %s", datapath.id, srcMac, dst, inPort)

            self.receive_arp(datapath, packets, etherFrame, inPort, data)
            return 0
        else:
            self.logger.debug("Drop packet")
            return 1
Exemplo n.º 3
0
    def _packet_in_handler(self, ev):
        self.logger.debug("my_arp: _packet_in_handler:")
        # If you hit this you might want to increase
        # the "miss_send_length" of your switch
        if ev.msg.msg_len < ev.msg.total_len:
            self.logger.debug("packet truncated: only %s of %s bytes",
                              ev.msg.msg_len, ev.msg.total_len)
        msg = ev.msg
        datapath = msg.datapath
        # ofproto = datapath.ofproto
        inPort = msg.match['in_port']
        packets = Packet(msg.data)
        dpid = datapath.id
        self.mac_to_port.setdefault(dpid, {})
        eth = packets.get_protocols(ethernet)[0]
        src = eth.src
        self.mac_to_port[dpid][src] = inPort
        data = msg.data

        # print "packets: ", packets
        # print "packets.get_protocols(ethernet): ", packets.get_protocols(ethernet)
        if etherFrame.ethertype == ether.ETH_TYPE_ARP:
            # print "packets: ", packets
            # print "packets.get_protocols(ethernet): ", packets.get_protocols(ethernet)
            self.receive_arp(datapath, packets, etherFrame, inPort, data)
            return 0
        else:
            self.logger.debug("Drop packet")
            return 1
Exemplo n.º 4
0
    def _packet_in_handler(self, ev):
        self.logger.debug("my_arp: _packet_in_handler:")
        # If you hit this you might want to increase
        # the "miss_send_length" of your switch
        if ev.msg.msg_len < ev.msg.total_len:
            self.logger.debug("packet truncated: only %s of %s bytes",
                              ev.msg.msg_len, ev.msg.total_len)
        msg = ev.msg
        datapath = msg.datapath
        # ofproto = datapath.ofproto
        inPort = msg.match['in_port']
        packets = Packet(msg.data)
        dpid = datapath.id

        eth = packets.get_protocols(ethernet)[0]
        src = eth.src
        dst = eth.dst

        self.mac_to_port.setdefault(hex(dpid), {})
        self.arp_learning.setdefault(dpid, [])
        self.packetToport.setdefault(dpid, {})

        if dst == LLDP_MAC_NEAREST_BRIDGE:
            return

        if src in self.mac_to_port[hex(dpid)].keys():
            pass
        else:
            self.mac_to_port[hex(dpid)][src] = inPort
        data = msg.data

        etherFrame = packets.get_protocol(ethernet)

        if etherFrame.ethertype == ether.ETH_TYPE_ARP:
            self.logger.debug("\n:")
            # arpPacket = packets.get_protocol(arp)
            # arpArriveTime = time.time()
            # srcMac = etherFrame.src
            # arp_dstIP = arpPacket.dst_ip
            dst = eth.dst

            self.receive_arp(datapath, packets, etherFrame, inPort, data)
            return 0
        else:
            self.logger.debug("Drop packet")
            return 1
Exemplo n.º 5
0
    def _packet_in_handler(self, ev):
        self.logger.debug("my_arp: _packet_in_handler:")
        # If you hit this you might want to increase
        # the "miss_send_length" of your switch
        if ev.msg.msg_len < ev.msg.total_len:
            self.logger.debug("packet truncated: only %s of %s bytes",
                              ev.msg.msg_len, ev.msg.total_len)
        msg = ev.msg
        datapath = msg.datapath
        # ofproto = datapath.ofproto
        inPort = msg.match['in_port']
        packets = Packet(msg.data)
        dpid = datapath.id

        eth = packets.get_protocols(ethernet)[0]
        src = eth.src
        dst = eth.dst

        self.mac_to_port.setdefault(hex(dpid), {})
        self.arp_learning.setdefault(dpid, [])
        self.packetToport.setdefault(dpid, {})

        if dst == LLDP_MAC_NEAREST_BRIDGE:
            return

        if src in self.mac_to_port[hex(dpid)].keys():
            pass
        else:
            self.mac_to_port[hex(dpid)][src] = inPort
        data = msg.data

        # print mac_to_port for verification
        # self.logger.info("MySimpleArp: self.mac_to_port")
        # for key, value in self.mac_to_port.items():
        #     print "\t", self._hostname_Check(int(str(key), 16)), value

        etherFrame = packets.get_protocol(ethernet)

        if etherFrame.ethertype == ether.ETH_TYPE_ARP:
            self.logger.debug("\n:")
            dst = eth.dst
            self.receive_arp(datapath, packets, etherFrame, inPort, data)
            return 0
        else:
            self.logger.debug("Drop packet")
            return 1
Exemplo n.º 6
0
    def _packet_in_handler(self, ev):
        self.logger.debug("my_arp: _packet_in_handler:")
        # If you hit this you might want to increase
        # the "miss_send_length" of your switch
        if ev.msg.msg_len < ev.msg.total_len:
            self.logger.debug("packet truncated: only %s of %s bytes", ev.msg.msg_len, ev.msg.total_len)
        msg = ev.msg
        datapath = msg.datapath
        # ofproto = datapath.ofproto
        inPort = msg.match["in_port"]
        packets = Packet(msg.data)
        dpid = datapath.id

        eth = packets.get_protocols(ethernet)[0]
        src = eth.src
        dst = eth.dst

        self.mac_to_port.setdefault(hex(dpid), {})
        self.arp_learning.setdefault(dpid, [])
        self.packetToport.setdefault(dpid, {})

        if dst == LLDP_MAC_NEAREST_BRIDGE:
            return

        if src in self.mac_to_port[hex(dpid)].keys():
            pass
        else:
            self.mac_to_port[hex(dpid)][src] = inPort
        data = msg.data

        etherFrame = packets.get_protocol(ethernet)

        if etherFrame.ethertype == ether.ETH_TYPE_ARP:
            self.logger.debug("\n:")
            # arpPacket = packets.get_protocol(arp)
            # arpArriveTime = time.time()
            # srcMac = etherFrame.src
            # arp_dstIP = arpPacket.dst_ip
            dst = eth.dst

            self.receive_arp(datapath, packets, etherFrame, inPort, data)
            return 0
        else:
            self.logger.debug("Drop packet")
            return 1
Exemplo n.º 7
0
    def _packet_in_handler(self, ev):
        msg = ev.msg
        datapath = msg.datapath
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser
        in_port = msg.match['in_port']

        pkt = Packet(msg.data)
        eth = pkt.get_protocols(ethernet)[0]

        dst = eth.dst
        src = eth.src

        dpid = datapath.id
        self.mac_to_port.setdefault(dpid, {})

        self.logger.info("packet in %s %s %s %s", dpid, src, dst, in_port)

        # learn a mac address to avoid FLOOD next time.
        self.mac_to_port[dpid][src] = in_port

        if dst in self.mac_to_port[dpid]:
            out_port = self.mac_to_port[dpid][dst]
        else:
            out_port = ofproto.OFPP_FLOOD

        actions = [parser.OFPActionOutput(out_port)]

        # install a flow to avoid packet_in next time
        if out_port != ofproto.OFPP_FLOOD:
            match = parser.OFPMatch(in_port=in_port, eth_dst=dst)
            self.add_flow(datapath, 1, match, actions)

        data = None
        if msg.buffer_id == ofproto.OFP_NO_BUFFER:
            data = msg.data

        out = parser.OFPPacketOut(datapath=datapath, buffer_id=msg.buffer_id,
                                  in_port=in_port, actions=actions, data=data)
        datapath.send_msg(out)