• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python arp.arp函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中ryu.lib.packet.arp.arp函数的典型用法代码示例。如果您正苦于以下问题:Python arp函数的具体用法?Python arp怎么用?Python arp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了arp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _handle_arp

    def _handle_arp(self, datapath, port, pkt_ethernet, pkt_arp):
        """Handle ARP reply/request packets.
        When controller get an ARP reply packet, it will write into ARP table.
        When controller get an ARP request packet,
        it will reply someone who want to ask NAT's MAC address.
        (Probably under NAT's LAN or WAN)"""
        if pkt_arp.opcode != arp.ARP_REQUEST:
            #it means ARP_REPLY
            if pkt_arp.dst_ip == self.nat_ip:
                # 140.92.62.30 is at xx:xx:xx:xx:xx:xx
                # Got an ARP Reply and parser it.
                #gw_src_mac = pkt_arp.src_mac
                #gw_ip = pkt_arp.src_ip
                ARP_TABLE[pkt_arp.src_ip] = pkt_arp.src_mac
                print "Get ARP reply"
                print ARP_TABLE
            return
        else:
            pass

        # Handle ARP Request and send an ARP Reply
        if pkt_arp.dst_ip == self.nat_intranet_gateway:
            # Who has 192.168.9.1 ?
            # Tell 192.168.9.20(Host), 192.168.9.1's fake MAC address (eth1)
            pkt = packet.Packet()
            pkt.add_protocol(ethernet.ethernet(ethertype=pkt_ethernet.ethertype,
                                               dst=pkt_ethernet.src,
                                               src=self.fake_mac_eth1))

            pkt.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
                                     src_mac=self.fake_mac_eth1,
                                     src_ip=self.nat_intranet_gateway,
                                     dst_mac=pkt_arp.src_mac,
                                     dst_ip=pkt_arp.src_ip))
            #print "Send pkt to %s" % pkt_arp.src_mac
            self._send_packet(datapath, port, pkt)
        elif pkt_arp.dst_ip == self.nat_ip:
            # Who has 140.92.62.235 ?
            # Tell 140.92.62.1(Extranet Gateway)
            pkt = packet.Packet()
            pkt.add_protocol(ethernet.ethernet(ethertype=pkt_ethernet.ethertype,
                                               dst=pkt_ethernet.src,
                                               src=self.fake_mac_eth2))

            pkt.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
                                     src_mac=self.fake_mac_eth1,
                                     src_ip=self.nat_ip,
                                     dst_mac=pkt_arp.src_mac,
                                     dst_ip=pkt_arp.src_ip))

            self._send_packet(datapath, port, pkt)
        else:
            return
开发者ID:John-Lin,项目名称:nat,代码行数:53,代码来源:snat.py


示例2: _handle_arp

 def _handle_arp(self, ev, subname):
     msg = ev.msg
     datapath = msg.datapath
     in_port = msg.match['in_port']
     
     pkt = packet.Packet(data=msg.data)
     pkt_ethernet = pkt.get_protocol(ethernet.ethernet)
     pkt_arp = pkt.get_protocol(arp.arp)
     
     if pkt_arp.opcode == arp.ARP_REPLY: 
         self.subnet[datapath.id][subname]['arp_table'][pkt_arp.src_ip]=pkt_arp.src_mac
         self.logger.info('arp_table: %s ' % json.dumps(self.subnet))  
         return
     
     elif pkt_arp.opcode == arp.ARP_REQUEST:
         #ingest arp_table
         self.subnet[datapath.id][subname]['arp_table'][pkt_arp.src_ip]=pkt_arp.src_mac
         self.logger.info('arp_table: %s ' % json.dumps(self.subnet))  
         
         this_subnet=self.subnet[datapath.id][subname]
         #generating arp packet
         pkt = packet.Packet()
         pkt.add_protocol(ethernet.ethernet(ethertype=pkt_ethernet.ethertype, dst=pkt_ethernet.src, src=this_subnet['mac']))
         pkt.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
             src_mac=this_subnet['mac'],
             src_ip =this_subnet['ip'],
             dst_mac=pkt_arp.src_mac,
             dst_ip=pkt_arp.src_ip))
         self._send_packet(datapath, in_port, pkt)
         self.logger.info("arp reply is sent: %s-%s -> %s-%s via port=%s" % (this_subnet['mac'], this_subnet['ip'], pkt_arp.src_mac, pkt_arp.src_ip, in_port) )
         return
     else:
         return
开发者ID:ktmrmshk,项目名称:OpenFlowRyuSwitches,代码行数:33,代码来源:basic_router.py


示例3: discover_router

 def discover_router(self, datapath, ofproto, parser):
     ##arp for the router first, to learn its out port
     ##form the ARP req
     a_hwtype = 1
     a_proto = ether.ETH_TYPE_IP
     a_hlen = 6
     a_plen = 4
     a_opcode = 1 #request1
     a_srcMAC = self.CONTROLLER_SPECIAL_MAC
     a_srcIP = self.CONTROLLER_SPECIAL_IP
     a_dstMAC = self.ROUTER_MAC
     a_dstIP = self.ROUTER_IP
     p = packet.Packet()
     e = ethernet.ethernet(a_dstMAC,a_srcMAC,ether.ETH_TYPE_ARP)
     a = arp.arp(a_hwtype,a_proto,a_hlen,a_plen,a_opcode,a_srcMAC,a_srcIP,a_dstMAC,a_dstIP)
     p.add_protocol(e)
     p.add_protocol(a)
     p.serialize()
     #send packet out
     actions = [parser.OFPActionOutput(ofproto.OFPP_FLOOD)]
     out = parser.OFPPacketOut(datapath=datapath, buffer_id=ofproto.OFP_NO_BUFFER,in_port=ofproto.OFPP_CONTROLLER, actions=actions, data=p.data)
     datapath.send_msg(out)
     dpid = datapath.id
     self.logger.info("packet out dpid:'%s' src:'%s' dst:'%s' out_port:'OFPP_FLOOD'", dpid, self.CONTROLLER_SPECIAL_MAC, self.ROUTER_MAC)
     self.logger.info("[ADMIN] Attempting to discover WAN router... ")
开发者ID:zubair1234,项目名称:Assignment,代码行数:25,代码来源:carrier.py


示例4: _handle_arp_overrider

    def _handle_arp_overrider(self, datapath, port, pkt_ethernet, pkt_arp):
        if pkt_arp.opcode != arp.ARP_REQUEST:
            return

        #Learn the MAC to IP
        mac_lst = []
        for each_key in GlobalTables.mac_to_port.keys():
	        x = GlobalTables.mac_to_port[each_key]
	        for mac,port in x.iteritems():
		        mac_lst.append(mac)

        if (pkt_arp.src_mac in mac_lst):
            self.learn_mac_to_ip(datapath.id, pkt_arp.src_mac, pkt_arp.src_ip)
            self.logger.info("INFO: New MAC_TO_IP: %s", GlobalTables.mac_to_ip)

        #Generate response
        pkt = packet.Packet()
        pkt.add_protocol(ethernet.ethernet(ethertype = pkt_ethernet.ethertype,
                                           dst = pkt_ethernet.src,
                                           src = GlobalTables.hw_addr))

        pkt.add_protocol(arp.arp(opcode = arp.ARP_REPLY,
                                 src_mac = '02:00:00:00:00:01',
                                 src_ip = pkt_arp.dst_ip,
                                 dst_mac = pkt_arp.src_mac,
                                 dst_ip = pkt_arp.src_ip))

        self.logger.info("INFO: Sending ARPOverrider response")
        self._send_packet(datapath, port, pkt)
开发者ID:vmetodiev,项目名称:SDN,代码行数:29,代码来源:ArpOverrider.py


示例5: addARP

 def addARP(pkt_out,fields):
     pkt_out.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
                          src_mac=fields['srcmac'],
                          src_ip=fields['srcip'],
                          dst_mac=fields['dstmac'],
                          dst_ip=fields['dstip']))
     return pkt_out
开发者ID:Ryuretic,项目名称:SecRev,代码行数:7,代码来源:Ryuretic.py


示例6: _arp_request

    def _arp_request(self, datapath, pkt_ip=None):
        """Sending an ARP request via broadcast"""
        # Who has xxx.xxx.xxx.xxx? Tell 140.92.62.235 (NAT's Public IP)
        if pkt_ip is None:
            target_ip = self.nat_extranet_gateway
        else:
            target_ip = self.subnet(pkt_ip)
        print "Sending ARP Request..."
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        #target_ip = self.subnet(pkt_ip)
        pkt = packet.Packet()
        pkt.add_protocol(ethernet.ethernet(ethertype=ether.ETH_TYPE_ARP,
                                           dst='ff:ff:ff:ff:ff:ff',
                                           src=self.fake_mac_eth2))

        pkt.add_protocol(arp.arp(opcode=arp.ARP_REQUEST,
                                 src_mac=self.fake_mac_eth2,
                                 src_ip=self.nat_ip,
                                 dst_mac='00:00:00:00:00:00',
                                 dst_ip=target_ip))
        pkt.serialize()
        data = pkt.data
        actions = [parser.OFPActionOutput(ofproto.OFPP_FLOOD)]
        out = parser.OFPPacketOut(datapath=datapath,
                                  buffer_id=ofproto.OFP_NO_BUFFER,
                                  in_port=ofproto.OFPP_CONTROLLER,
                                  actions=actions,
                                  data=data)
        datapath.send_msg(out)
开发者ID:John-Lin,项目名称:nat,代码行数:31,代码来源:snat.py


示例7: receive_ip

    def receive_ip(self, datapath, packet, etherFrame, inPort, msg): #Función que se usa cuando se recibe un paquete IP
        ipPacket = packet.get_protocol(ipv4.ipv4)

        if ipPacket.dst == self.ports_to_ips[0][0]: #Si va destinado al router
            if ipPacket.proto == inet.IPPROTO_ICMP:
                icmpPacket = packet.get_protocol(icmp.icmp)
                self.check_icmp(datapath, etherFrame, ipPacket, icmpPacket, inPort) #Se usa una función que trata un paquete ICMP 
                return 0
            else:
                send_packet(datapath=datapath,port=inPort,packet=packet) #Se envía el paquete
                return 1
        else: #Si no va destinado al router
            (next_hop, port) = self.find_in_routingTable(ipPacket.dst) #Almacena el puerto y el siguiente salto
            #en port y en next_hop
            if next_hop in self.ipToMac.keys(): #Si está dentro de la tabla de ips y macs se envía.
                match = datapath.ofproto_parser.OFPMatch(eth_dst=self.ipToMac[next_hop]) 
                actions = [datapath.ofproto_parser.OFPActionOutput(port)]

                #self.add_flow(datapath, 0, match, actions)
                self.insertar_flujo(msg=msg, mac=self.ipToMac[next_hop], port=port, mod=1)
            else: #Si no está dentro de la tabla se construye un paquete ARP para averiguar su MAC
                # print "---- NEXT_HOP -----", next_hop
                e = ethernet.ethernet(src=etherFrame.dst, ethertype=ether.ETH_TYPE_ARP)
                a = arp.arp(opcode=arp.ARP_REQUEST,
                            src_ip=self.ports_to_ips[port-1][0],
                            src_mac=etherFrame.src,
                            dst_ip=next_hop)
                puerto = etherFrame.src
                p = Packet()
                p.add_protocol(e)
                p.add_protocol(a)
                if next_hop not in self.dict_pendientes:
                    self.dict_pendientes[next_hop] = []
                self.dict_pendientes[next_hop] = self.dict_pendientes[next_hop] + [(msg, port,None,None)]
                self.send_packet(datapath=datapath, port=port, packet=p)
开发者ID:Madh93,项目名称:NatRouter,代码行数:35,代码来源:PAT.py


示例8: _arp_proxy_handler

    def _arp_proxy_handler(self, ev):
        msg = ev.msg
        pkt = ev.pkt

        datapath = msg.datapath
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser
        in_port = msg.match["in_port"]

        eth_protocol = pkt.get_protocol(ethernet.ethernet)
        eth_src = eth_protocol.src

        arp_protocol = pkt.get_protocol(arp.arp)

        src_ip = arp_protocol.src_ip
        dst_ip = arp_protocol.dst_ip

        self.arp_table[src_ip] = eth_src

        self.dp_to_ip[datapath.id].add(src_ip)
        if arp_protocol.opcode == arp.ARP_REPLY:
            return

        dst_mac = self.arp_table.get(dst_ip)
        if dst_mac is None:
            # Flood to flood_ports
            ports = self.wrapper.get_flood_ports()
            for dpid, out_port in ports:
                if (dpid, out_port) == (datapath.id, in_port):
                    continue
                self.logger.info("flood to port:%d:%d", dpid, out_port)
                dp = self.dpset.get(dpid)
                actions = [parser.OFPActionOutput(out_port)]
                out = dp.ofproto_parser.OFPPacketOut(datapath=dp,
                                                     buffer_id=dp.ofproto.OFP_NO_BUFFER,
                                                     in_port=dp.ofproto.OFPP_CONTROLLER,
                                                     actions=actions,
                                                     data=msg.data)
                dp.send_msg(out)
        else:
            ARP_Reply = packet.Packet()
            ARP_Reply.add_protocol(ethernet.ethernet(ethertype=eth_protocol.ethertype,
                                                     dst=eth_src,
                                                     src=dst_mac))
            ARP_Reply.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
                                           src_mac=dst_mac,
                                           src_ip=dst_ip,
                                           dst_mac=eth_src,
                                           dst_ip=src_ip))
            ARP_Reply.serialize()

            actions = [parser.OFPActionOutput(in_port)]
            out = parser.OFPPacketOut(datapath=datapath,
                                      buffer_id=ofproto.OFP_NO_BUFFER,
                                      in_port=ofproto.OFPP_CONTROLLER,
                                      actions=actions,
                                      data=ARP_Reply.data)
            datapath.send_msg(out)
            self.logger.debug("%s - %s" % (dst_ip, dst_mac))
            return True
开发者ID:Yokoloki,项目名称:sStreaming,代码行数:60,代码来源:arp_proxy.py


示例9: _handle_arp_reply

 def _handle_arp_reply(self, pkt_arp, port, dpid):
     if pkt_arp.opcode == arp.ARP_REPLY and pkt_arp.dst_mac == self.hw_addr:
         if pkt_arp.src_ip not in self.active_ips:
             print("ARP from " + pkt_arp.src_ip + "\n")
             self.active_ips[pkt_arp.src_ip] =  [dpid, port]
             self.arp_table[pkt_arp.src_ip] = pkt_arp.src_mac
             if self.topology:
                 self.draw_graph(1, draw=True)
     if pkt_arp.opcode == arp.ARP_REQUEST and pkt_arp.src_ip != self.ip_addr:
     #print("ARP Reqest from: " + pkt_arp.src_mac + " requesting: " + pkt_arp.dst_ip)
         if pkt_arp.dst_ip not in self.arp_table: return
         #construct and send ARP reply
         reply_pkt = packet.Packet()
         reply_pkt.add_protocol(ethernet.ethernet(ethertype=0x806,\
                                            dst=pkt_arp.src_mac,\
                                            src=self.arp_table[pkt_arp.dst_ip]))
         reply_pkt.add_protocol(arp.arp(opcode=arp.ARP_REPLY,\
                              src_mac=self.arp_table[pkt_arp.dst_ip],\
                              src_ip=pkt_arp.dst_ip,\
                              dst_mac=pkt_arp.src_mac,\
                              dst_ip=pkt_arp.src_ip))
         print("Responded to ARP Request: " )
         print("Gave [" + pkt_arp.src_mac + "," + pkt_arp.src_ip + "]" +\
         "[" + pkt_arp.dst_ip + "," + self.arp_table[pkt_arp.dst_ip] + "]") 
         self._send_packet(reply_pkt, self.dpids[int(dpid, 16)]) 
开发者ID:npsccw,项目名称:SDN-Applications,代码行数:25,代码来源:ControlNode.py


示例10: find_mac

    def find_mac(self, datapath, etherFrame, msg):

        #Almacena el puerto y el siguiente salto
        (next_hop, port) = self.find_in_routingTable(ipPacket.dst) 

        if next_hop in self.ipToMac.keys(): #Si está dentro de la tabla de ips y macs se envía.
            match = datapath.ofproto_parser.OFPMatch(eth_dst=self.ipToMac[next_hop]) 
            actions = [datapath.ofproto_parser.OFPActionOutput(port)]

            self.add_flow(datapath, 0, match, actions)
            self.insertar_flujo(msg=msg, mac=self.ipToMac[next_hop], port=port, mod=1)
        else: #Si no está dentro de la tabla se construye un paquete ARP para averiguar su MAC
            # print "---- NEXT_HOP -----", next_hop
            e = ethernet.ethernet(src=etherFrame.dst, ethertype=ether.ETH_TYPE_ARP)
            a = arp.arp(opcode=arp.ARP_REQUEST,
                        src_ip=self.ports_to_ips[port-1][0],
                        src_mac=etherFrame.src,
                        dst_ip=next_hop)
            puerto = etherFrame.src
            p = Packet()
            p.add_protocol(e)
            p.add_protocol(a)
            if next_hop not in self.dict_pendientes:
                self.dict_pendientes[next_hop] = []
            self.dict_pendientes[next_hop] = self.dict_pendientes[next_hop] + [(msg, port, None, None)]
            self.send_packet(datapath=datapath, port=port, packet=p)
开发者ID:Madh93,项目名称:NatRouter,代码行数:26,代码来源:PAT.py


示例11: createArpReply

def createArpReply(message, ip):
    if not packetIsARP(message):
        print("Packet is not ARP")
        return
    pkt = packet.Packet(message.data)
    origarp = pkt.get_protocol(arp.arp)
    a = arp.arp(
        hwtype=origarp.hwtype,
        proto=origarp.proto,
        src_mac=origarp.src_mac,
        dst_mac=origarp.dst_mac,
        hlen=origarp.hlen,
        opcode=arp.ARP_REPLY,
        plen=origarp.plen,
        src_ip=ip,
        dst_ip=origarp.dst_ip
        )
    e = ethernet.ethernet(
        dst=origarp.dst_mac,
        src=origarp.src_mac,
        ethertype=ether.ETH_TYPE_ARP)
    p = packet.Packet()
    p.add_protocol(e)
    p.add_protocol(a)
    p.serialize()
    return p
开发者ID:zhewangjoe,项目名称:of,代码行数:26,代码来源:utils.py


示例12: receive_arp

    def receive_arp(self, datapath, packet, etherFrame, inPort):

        arp_msg = packet.get_protocol(arp.arp)

        if arp_msg.opcode == arp.ARP_REQUEST:
            if arp_msg.dst_ip == self.ports_to_ips[inPort-1][0]:
                e = ethernet.ethernet(dst=etherFrame.src,
                                        src=self.ports_to_ips[inPort-1][2],
                                        ethertype=ether.ETH_TYPE_ARP)
                a = arp.arp(opcode=arp.ARP_REPLY,
                            src_mac=self.ports_to_ips[inPort-1][2],
                            src_ip=arp_msg.dst_ip,
                            dst_mac=etherFrame.src,
                            dst_ip=arp_msg.src_ip)
                puerto=inPort
                p = Packet()
                p.add_protocol(e)
                p.add_protocol(a)

                self.send_packet(datapath, puerto, p)
        
        elif arp_msg.opcode == arp.ARP_REPLY:
            self.ipToMac[arp_msg.src_ip] = arp_msg.src_mac
            for (msg,port,nat,puertoNat) in self.dict_pendientes[arp_msg.src_ip]:
                if nat == None and puertoNat == None:
                    self.insertar_flujo(msg=msg, mac=arp_msg.src_mac, port=port, mod=1)
                elif nat == 1:
                    self.insertar_flujo(msg=msg, mod=0, puerto_origen=puertoNat, ip_origen=ip_publica, sentido=1, protoc=1, port=port, mac=arp_msg.src_mac)
            self.dict_pendientes[arp_msg.src_ip] = []
开发者ID:Madh93,项目名称:NatRouter,代码行数:29,代码来源:PAT.py


示例13: arp_reply

	def arp_reply(self,datapath, src, dst, dst_ip, src_ip, eth, msg):
        
		ofproto = datapath.ofproto
        
		parser = datapath.ofproto_parser
        
		pkt = packet.Packet()
        
		pkt.add_protocol(ethernet.ethernet(ethertype=eth.ethertype, dst=src, src=dst))
        
		pkt.add_protocol(arp.arp(opcode=2, src_mac=dst, src_ip=dst_ip, dst_mac=src, dst_ip=src_ip))
        
		pkt.serialize()
        
		self.logger.info("packet-out %s", pkt)

        
		
		actions = [parser.OFPActionOutput(port=msg.in_port)]
        
		data = pkt.data
     
        
		out = parser.OFPPacketOut(datapath=datapath,
                                  
		      buffer_id=ofproto.OFP_NO_BUFFER,
                                  
                      in_port=ofproto.OFPP_CONTROLLER,
                                  
                      actions=actions,
                                  
                      data=data)
        
		datapath.send_msg(out)
开发者ID:Abmuthu,项目名称:sdn_controller,代码行数:34,代码来源:Controller+script.py


示例14: handle_arp

	def handle_arp(self, dp, port, pkt_ethernet, pkt_arp):
		if pkt_arp.opcode != arp.ARP_REQUEST:
			return
		
		if self.arp_table.get(pkt_arp.dst_ip) == None:
			return
		get_mac = self.arp_table[pkt_arp.dst_ip]
		

		pkt = packet.Packet()
		pkt.add_protocol(
			ethernet.ethernet(
				ethertype=ether.ETH_TYPE_ARP,
				dst = pkt_ethernet.src,
				src = get_mac
			)
		)

		pkt.add_protocol(
			arp.arp(
				opcode=arp.ARP_REPLY,
				src_mac= get_mac,
				src_ip = pkt_arp.dst_ip,
				dst_mac= pkt_arp.src_mac,
				dst_ip = pkt_arp.src_ip 
			)
		)

		self.send_packet(dp, port, pkt)
开发者ID:imac-cloud,项目名称:SDN-tutorial,代码行数:29,代码来源:shortest_path_with_networkx.py


示例15: request_generator

    def request_generator(self,datapath):
        
        parser = datapath.ofproto_parser
        barrier_req = parser.OFPBarrierRequest(datapath)

        e = ethernet.ethernet(dst='ff:ff:ff:ff:ff:ff',
                              src='08:60:6e:7f:74:e7',
                              ethertype=ether.ETH_TYPE_ARP)
        a = arp.arp(hwtype=1, proto=0x0800, hlen=6, plen=4, opcode=2,
                    src_mac='08:60:6e:7f:74:e7', src_ip='192.0.2.1',
                    dst_mac='00:00:00:00:00:00', dst_ip='192.0.2.2')
        p = packet.Packet()
        p.add_protocol(e)
        p.add_protocol(a)
        p.serialize()
        msg1=p.data

        actions = [parser.OFPActionOutput(1, 0)]
        send_data_req = parser.OFPPacketOut(datapath, buffer_id=0xffffffff, in_port=datapath.ofproto.OFPP_CONTROLLER, actions=actions, data=p.data)

        print "send empty request"
        datapath.send_msg(barrier_req)
        yield
        print "send 1st datamsg"
        datapath.send_msg(send_data_req)
        datapath.send_msg(barrier_req)
        yield
        print "send 2nd datamsg"
        datapath.send_msg(send_data_req)
        datapath.send_msg(barrier_req)
        yield
        print "*** end of request sequence ***"
        yield
开发者ID:hdb3,项目名称:custom_tables,代码行数:33,代码来源:custom_switch.py


示例16: build_pkt

def build_pkt(pkt):
    layers = []
    if 'arp_target_ip' in pkt:
        ethertype = 0x806
        layers.append(arp.arp(dst_ip=pkt['arp_target_ip']))
    elif 'ipv6_src' in pkt:
        ethertype = 0x86DD
        layers.append(ipv6.ipv6(src=pkt['ipv6_src'], dst=pkt['ipv6_src']))
    else:
        ethertype = 0x800
        if 'ipv4_src' in pkt:
            net = ipv4.ipv4(src=pkt['ipv4_src'], dst=pkt['ipv4_dst'])
        else:
            net = ipv4.ipv4()
        layers.append(net)
    if 'vid' in pkt:
        tpid = 0x8100
        layers.append(vlan.vlan(vid=pkt['vid'], ethertype=ethertype))
    else:
        tpid = ethertype
    eth = ethernet.ethernet(
        dst=pkt['eth_dst'],
        src=pkt['eth_src'],
        ethertype=tpid)
    layers.append(eth)
    result = packet.Packet()
    for layer in layers:
        result.add_protocol(layer)
    return result
开发者ID:Baloc,项目名称:faucet,代码行数:29,代码来源:test_valve.py


示例17: control_plane_arp_handler

    def control_plane_arp_handler(self, in_port, vlan, eth_src, arp_pkt):
        ofmsgs = []

        if arp_pkt.opcode == arp.ARP_REQUEST:
            pkt = self.build_ethernet_pkt(
                eth_src, in_port, vlan, ether.ETH_TYPE_ARP)
            arp_pkt = arp.arp(
                opcode=arp.ARP_REPLY, src_mac=self.FAUCET_MAC,
                src_ip=arp_pkt.dst_ip, dst_mac=eth_src, dst_ip=arp_pkt.src_ip)
            pkt.add_protocol(arp_pkt)
            pkt.serialize()
            ofmsgs.append(self.valve_packetout(in_port, pkt.data))
            self.logger.info('Responded to ARP request for %s from %s',
                arp_pkt.src_ip, arp_pkt.dst_ip)
        elif arp_pkt.opcode == arp.ARP_REPLY:
            resolved_ip_gw = ipaddr.IPv4Address(arp_pkt.src_ip)
            for ip_dst, ip_gw in vlan.ipv4_routes.iteritems():
                if ip_gw == resolved_ip_gw:
                    self.logger.info('ARP response %s for %s',
                        eth_src, resolved_ip_gw)
                    ofmsgs.extend(
                        self.add_resolved_route(
                            ether.ETH_TYPE_IP, vlan, vlan.arp_cache,
                            ip_gw, ip_dst, eth_src))

        return ofmsgs
开发者ID:dr-clark,项目名称:faucet,代码行数:26,代码来源:valve.py


示例18: _respond_arp

 def _respond_arp(self, datapath, port, arptbl,
                  pkt_ethernet, pkt_vlan, pkt_arp):
     if pkt_arp.opcode != arp.ARP_REQUEST:
         LOG.debug("unknown arp op %s", pkt_arp.opcode)
         return False
     ip_addr = pkt_arp.dst_ip
     hw_addr = arptbl.get(ip_addr)
     if hw_addr is None:
         LOG.debug("unknown arp request %s", ip_addr)
         return False
     LOG.debug("responding arp request %(ip_addr)s -> %(hw_addr)s",
               {'ip_addr': ip_addr, 'hw_addr': hw_addr})
     pkt = packet.Packet()
     pkt.add_protocol(ethernet.ethernet(ethertype=pkt_ethernet.ethertype,
                                        dst=pkt_ethernet.src,
                                        src=hw_addr))
     if pkt_vlan:
         pkt.add_protocol(vlan.vlan(cfi=pkt_vlan.cfi,
                                    ethertype=pkt_vlan.ethertype,
                                    pcp=pkt_vlan.pcp,
                                    vid=pkt_vlan.vid))
     pkt.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
                              src_mac=hw_addr,
                              src_ip=ip_addr,
                              dst_mac=pkt_arp.src_mac,
                              dst_ip=pkt_arp.src_ip))
     self._send_arp_reply(datapath, port, pkt)
     return True
开发者ID:asadoughi,项目名称:neutron,代码行数:28,代码来源:arp_lib.py


示例19: handle_arp

    def handle_arp(self, datapath, in_port, pkt):
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        # parse out the ethernet and arp packet
        eth_pkt = pkt.get_protocol(ethernet.ethernet)
        arp_pkt = pkt.get_protocol(arp.arp)
        # obtain the MAC of dst IP  
        arp_resolv_mac = self.arp_table[arp_pkt.dst_ip]

        # generate the ARP reply msg
        # the packet library section

        ether_hd = ethernet.ethernet(dst = eth_pkt.src, 
                                src = arp_resolv_mac, 
                                ethertype = ether.ETH_TYPE_ARP);
        arp_hd = arp.arp(hwtype=1, proto = 2048, hlen = 6, plen = 4,
                         opcode = 2, src_mac = arp_resolv_mac, 
                         src_ip = arp_pkt.dst_ip, dst_mac = eth_pkt.src,
                         dst_ip = arp_pkt.src_ip);
        arp_reply = packet.Packet()
        arp_reply.add_protocol(ether_hd)
        arp_reply.add_protocol(arp_hd)
	arp_reply.serialize()
       



        
        # send the Packet Out mst to back to the host who is initilaizing the ARP
        actions = [parser.OFPActionOutput(in_port)];
        out = parser.OFPPacketOut(datapath, ofproto.OFP_NO_BUFFER, 
                                  ofproto.OFPP_CONTROLLER, actions,
                                  arp_reply.data)
        datapath.send_msg(out)
开发者ID:gevmanekshaw,项目名称:Data-Centers-and-Cloud-Computing,代码行数:35,代码来源:controller4.py


示例20: create_arp

def create_arp(dl_src, dl_dst, nl_src, nl_dst):
    '''
    Create an ARP reply packet.

    :param dl_src: 48bit MAC address
    :type dl_src: str

    :param dl_dst: 48bit MAC address
    :type dl_dst: str

    :param nl_src: 32bit IP address
    :type nl_src: str

    :param nl_dst: 32bit IP address
    :type nl_dst: str

    :returns: binary representation of ARP packet
    :rtype: `bytearray`
    '''
    pkt = packet.Packet()
    pkt.add_protocol(ethernet.ethernet(ethertype=ethertypes.ETH_TYPE_ARP,
                                       dst=dl_dst,
                                       src=dl_src))
    pkt.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
                             src_mac=dl_src,
                             src_ip=nl_src,
                             dst_mac=dl_dst,
                             dst_ip=nl_dst))
    return pkt.serialize()
开发者ID:illotum,项目名称:sdn-fabric,代码行数:29,代码来源:packet.py



注:本文中的ryu.lib.packet.arp.arp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python icmp.icmp函数代码示例发布时间:2022-05-27
下一篇:
Python pack_utils.msg_pack_into函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap