当前位置: 首页>>代码示例>>Python>>正文


Python arp.ARP_REPLY属性代码示例

本文整理汇总了Python中ryu.lib.packet.arp.ARP_REPLY属性的典型用法代码示例。如果您正苦于以下问题:Python arp.ARP_REPLY属性的具体用法?Python arp.ARP_REPLY怎么用?Python arp.ARP_REPLY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在ryu.lib.packet.arp的用法示例。


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

示例1: arp_parse

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REPLY [as 别名]
def arp_parse(data):
        """
        Parse ARP packet, return ARP class from packet library.
        """
        # Iteratize pkt
        pkt = packet.Packet(data)
        i = iter(pkt)
        eth_pkt = next(i)
        # Ensure it's an ethernet frame.
        assert type(eth_pkt) == ethernet.ethernet

        arp_pkt = next(i)
        if type(arp_pkt) != arp.arp:
            raise ARPPacket.ARPUnknownFormat()

        if arp_pkt.opcode not in (ARP_REQUEST, ARP_REPLY):
            raise ARPPacket.ARPUnknownFormat(
                msg='unsupported opcode %d' % arp_pkt.opcode)

        if arp_pkt.proto != ETH_TYPE_IP:
            raise ARPPacket.ARPUnknownFormat(
                msg='unsupported arp ethtype 0x%04x' % arp_pkt.proto)

        return arp_pkt 
开发者ID:lagopus,项目名称:ryu-lagopus-ext,代码行数:26,代码来源:bfdlib.py

示例2: _build_arp

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REPLY [as 别名]
def _build_arp(self, opcode, dst_ip=HOST_IP):
        if opcode == arp.ARP_REQUEST:
            _eth_dst_mac = self.BROADCAST_MAC
            _arp_dst_mac = self.ZERO_MAC
        elif opcode == arp.ARP_REPLY:
            _eth_dst_mac = self.HOST_MAC
            _arp_dst_mac = self.HOST_MAC

        e = self._build_ether(ether.ETH_TYPE_ARP, _eth_dst_mac)
        a = arp.arp(hwtype=1, proto=ether.ETH_TYPE_IP, hlen=6, plen=4,
                    opcode=opcode, src_mac=self.RYU_MAC, src_ip=self.RYU_IP,
                    dst_mac=_arp_dst_mac, dst_ip=dst_ip)
        p = packet.Packet()
        p.add_protocol(e)
        p.add_protocol(a)
        p.serialize()

        return p 
开发者ID:lagopus,项目名称:ryu-lagopus-ext,代码行数:20,代码来源:test_arp.py

示例3: receive_arp

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REPLY [as 别名]
def receive_arp(self, datapath, pkt, etherFrame, inPort):
        arpPacket = pkt.get_protocol(arp.arp)

        if arpPacket.opcode == arp.ARP_REQUEST:
            arp_dstIp = arpPacket.dst_ip

            # From the dest IP figure out the mac address
            targetMac = etherFrame.src
            targetIp = arpPacket.src_ip
            srcMac = ipToMac(arp_dstIp) # Get the MAC address of the ip looked up

            e = ethernet.ethernet(targetMac, srcMac, ether_types.ETH_TYPE_ARP)
            a = arp.arp(opcode=arp.ARP_REPLY, src_mac=srcMac, src_ip=arp_dstIp, dst_mac=targetMac, dst_ip=targetIp)
            p = packet.Packet()
            p.add_protocol(e)
            p.add_protocol(a)
            p.serialize()

            ofproto = datapath.ofproto
            parser = datapath.ofproto_parser
            datapath.send_msg(parser.OFPPacketOut(datapath=datapath, buffer_id=ofproto.OFP_NO_BUFFER, in_port=ofproto.OFPP_CONTROLLER, actions=[ parser.OFPActionOutput(inPort) ], data=p.data))

        elif arpPacket.opcode == ARP_REPLY:
            pass 
开发者ID:UofG-netlab,项目名称:sdnfv-ddos,代码行数:26,代码来源:ddosrouting.py

示例4: _handle_arp

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REPLY [as 别名]
def _handle_arp(self, datapath, in_port, eth_pkt, arp_pkt):
		if arp_pkt.opcode != arp.ARP_REQUEST:
			return
		#Browse Target hardware adress from ip_to_mac table.
		target_hw_addr = self.ip_to_mac[arp_pkt.dst_ip]
		target_ip_addr = arp_pkt.dst_ip

		pkt = packet.Packet()
		#Create ethernet packet
		pkt.add_protocol(ethernet.ethernet(ethertype=eth_pkt.ethertype,
											dst=eth_pkt.src,
											src=target_hw_addr))
		#Create ARP Reply packet
		pkt.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
								src_mac=target_hw_addr,
								src_ip=target_ip_addr,
								dst_mac=arp_pkt.src_mac,
								dst_ip=arp_pkt.src_ip))

		self._send_packet(datapath, in_port, pkt) 
开发者ID:ray6,项目名称:sdn,代码行数:22,代码来源:shortest_path_switch.py

示例5: arp_parse

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REPLY [as 别名]
def arp_parse(data):
        """
        Parse ARP packet, return ARP class from packet library.
        """
        # Iteratize pkt
        pkt = packet.Packet(data)
        i = iter(pkt)
        eth_pkt = next(i)
        # Ensure it's an ethernet frame.
        assert isinstance(eth_pkt, ethernet.ethernet)

        arp_pkt = next(i)
        if not isinstance(arp_pkt, arp.arp):
            raise ARPPacket.ARPUnknownFormat()

        if arp_pkt.opcode not in (ARP_REQUEST, ARP_REPLY):
            raise ARPPacket.ARPUnknownFormat(
                msg='unsupported opcode %d' % arp_pkt.opcode)

        if arp_pkt.proto != ETH_TYPE_IP:
            raise ARPPacket.ARPUnknownFormat(
                msg='unsupported arp ethtype 0x%04x' % arp_pkt.proto)

        return arp_pkt 
开发者ID:openstack,项目名称:deb-ryu,代码行数:26,代码来源:bfdlib.py

示例6: _arp_reply

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REPLY [as 别名]
def _arp_reply(self):
        p = self._build_arp(arp.ARP_REPLY, self.HOST_IP)
        return p.data 
开发者ID:lagopus,项目名称:ryu-lagopus-ext,代码行数:5,代码来源:test_arp.py

示例7: _handle_arp

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REPLY [as 别名]
def _handle_arp(self,datapath,in_port,pkt_eth,pkt_arp):
		if pkt_arp.opcode != arp.ARP_REQUEST:
			return
		pkt = packet.Packet()
		pkt.add_protocol(ethernet.ethernet(ethertype=pkt_eth.ethertype,
						dst=pkt_eth.src,src=self.hw_addr))
		pkt.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
						src_mac=self.hw_addr,
						src_ip=self.ip_addr,
						dst_mac=pkt_arp.src_mac,
						dst_ip=pkt_arp.src_ip))
		self._send_packet(datapath,in_port,pkt) 
开发者ID:ray6,项目名称:sdn,代码行数:14,代码来源:simple_switch.py

示例8: _handle_arp

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REPLY [as 别名]
def _handle_arp(self,datapath,in_port,pkt_eth,pkt_arp):
		if pkt_arp.opcode != arp.ARP_REQUEST:
			return
		pkt = packet.Packet()
		pkt.add_protocol(ethernet.ethernet(ethertype=pkt_eth.ethertype,
						dst=pkt_eth.src,src=self.hw_addr))
		pkt.add_protocol(arp.arp(opcode=arp.ARP_REPLY,
					src_mac=self.hw_addr,
					src_ip=self.ip_addr,
					dst_mac=pkt_arp.src_mac,
					dst_ip=pkt_arp.src_ip))
		self._send_packet(datapath,in_port,pkt) 
开发者ID:ray6,项目名称:sdn,代码行数:14,代码来源:stp_switch.py

示例9: _add_arp_reply_flow

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REPLY [as 别名]
def _add_arp_reply_flow(self, datapath, tag, arp_tpa, arp_tha):
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        match = parser.OFPMatch(
            metadata=(tag, parser.UINT64_MAX),
            eth_type=ether_types.ETH_TYPE_ARP,
            arp_op=arp.ARP_REQUEST,
            arp_tpa=arp_tpa)

        actions = [
            parser.NXActionRegMove(
                src_field="eth_src", dst_field="eth_dst", n_bits=48),
            parser.OFPActionSetField(eth_src=arp_tha),
            parser.OFPActionSetField(arp_op=arp.ARP_REPLY),
            parser.NXActionRegMove(
                src_field="arp_sha", dst_field="arp_tha", n_bits=48),
            parser.NXActionRegMove(
                src_field="arp_spa", dst_field="arp_tpa", n_bits=32),
            parser.OFPActionSetField(arp_sha=arp_tha),
            parser.OFPActionSetField(arp_spa=arp_tpa),
            parser.OFPActionOutput(ofproto.OFPP_IN_PORT)]
        instructions = [
            parser.OFPInstructionActions(
                ofproto.OFPIT_APPLY_ACTIONS, actions)]

        self._add_flow(datapath, PRIORITY_ARP_REPLAY, match, instructions,
                       table_id=TABLE_ID_EGRESS) 
开发者ID:openstack,项目名称:deb-ryu,代码行数:30,代码来源:rest_vtep.py

示例10: control_plane_arp_handler

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REPLY [as 别名]
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:onfsdn,项目名称:noc,代码行数:28,代码来源:valve.py

示例11: handle_control_plane

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REPLY [as 别名]
def handle_control_plane(self, in_port, vlan, eth_src, eth_dst, pkt):
        flowmods = []
        if eth_dst == self.FAUCET_MAC or not mac_addr_is_unicast(eth_dst):
            arp_pkt = pkt.get_protocol(arp.arp)
            ipv4_pkt = pkt.get_protocol(ipv4.ipv4)
            ipv6_pkt = pkt.get_protocol(ipv6.ipv6)

            if arp_pkt is not None:
                src_ip = ipaddr.IPv4Address(arp_pkt.src_ip)
                dst_ip = ipaddr.IPv4Address(arp_pkt.dst_ip)
                if (arp_pkt.opcode == arp.ARP_REQUEST and
                        self.to_faucet_ip(vlan, src_ip, dst_ip)):
                    flowmods.extend(self.control_plane_arp_handler(
                        in_port, vlan, eth_src, arp_pkt))
                elif (arp_pkt.opcode == arp.ARP_REPLY and
                              eth_dst == self.FAUCET_MAC):
                    flowmods.extend(self.control_plane_arp_handler(
                        in_port, vlan, eth_src, arp_pkt))
            elif ipv4_pkt is not None:
                icmp_pkt = pkt.get_protocol(icmp.icmp)
                if icmp_pkt is not None:
                    src_ip = ipaddr.IPv4Address(ipv4_pkt.src)
                    dst_ip = ipaddr.IPv4Address(ipv4_pkt.dst)
                    if self.to_faucet_ip(vlan, src_ip, dst_ip):
                        flowmods.extend(self.control_plane_icmp_handler(
                            in_port, vlan, eth_src, ipv4_pkt, icmp_pkt))
            elif ipv6_pkt is not None:
                icmpv6_pkt = pkt.get_protocol(icmpv6.icmpv6)
                if icmpv6_pkt is not None:
                    src_ip = ipaddr.IPv6Address(ipv6_pkt.src)
                    dst_ip = ipaddr.IPv6Address(ipv6_pkt.dst)
                    if self.to_faucet_ip(vlan, src_ip, dst_ip):
                        flowmods.extend(self.control_plane_icmpv6_handler(
                            in_port, vlan, eth_src, ipv6_pkt, icmpv6_pkt))

        return flowmods 
开发者ID:onfsdn,项目名称:noc,代码行数:38,代码来源:valve.py

示例12: arp_packet_in_handler

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REPLY [as 别名]
def arp_packet_in_handler(self, ev):
        msg = ev.msg
        datapath = msg.datapath
        in_port = msg.match['in_port']
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser
        pkt = packet.Packet(msg.data)
        arp_header = pkt.get_protocol(arp.arp)
        src_ip = arp_header.src_ip
        src_mac = arp_header.src_mac
        dst_ip = arp_header.dst_ip
        dst_mac = None

        if self.cfg_mgr.is_internal_host(src_ip):
            # if internal host sent arp request, reply router mac address
            first_speaker_id = None

            if self.cfg_mgr.get_all_speaker_id():
                first_speaker_id = self.cfg_mgr.get_all_speaker_id()[0]

            if first_speaker_id:
                dst_mac = self.cfg_mgr.get_speaker_mac(first_speaker_id)
        else:
            dst_mac = self.arp_table.get(dst_ip)

        self.arp_table.setdefault(src_ip, src_mac)

        if arp_header.opcode != arp.ARP_REQUEST:
            return

        if not dst_mac:
            # can't find distination, drop it
            return

        # send arp request to host
        actions = [parser.OFPActionOutput(in_port)]
        arp_reply = packet.Packet()
        arp_reply.add_protocol(
            ethernet.ethernet(
                ethertype=ether_types.ETH_TYPE_ARP,
                src=dst_mac,
                dst=src_mac
            )
        )
        arp_reply.add_protocol(
            arp.arp(
                opcode=arp.ARP_REPLY,
                src_ip=dst_ip,
                src_mac=dst_mac,
                dst_ip=src_ip,
                dst_mac=src_mac
            )
        )
        arp_reply.serialize()

        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) 
开发者ID:sdnds-tw,项目名称:Ryu-SDN-IP,代码行数:63,代码来源:arp_proxy.py

示例13: _packet_in_handler

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REPLY [as 别名]
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.Packet(msg.data)

        # If there's someone asked for an IP address associated
        # with a BFD session, generate an ARP reply for it.
        if arp.arp in pkt:
            arp_pkt = ARPPacket.arp_parse(msg.data)
            if arp_pkt.opcode == ARP_REQUEST:
                for s in self.session.values():
                    if s.dpid == datapath.id and \
                            s.ofport == in_port and \
                            s.src_ip == arp_pkt.dst_ip:

                        ans = ARPPacket.arp_packet(
                            ARP_REPLY,
                            s.src_mac, s.src_ip,
                            arp_pkt.src_mac, arp_pkt.src_ip)

                        actions = [parser.OFPActionOutput(in_port)]
                        out = parser.OFPPacketOut(
                            datapath=datapath,
                            buffer_id=ofproto.OFP_NO_BUFFER,
                            in_port=ofproto.OFPP_CONTROLLER,
                            actions=actions, data=ans)

                        datapath.send_msg(out)
                        return
            return

        # Check whether it's BFD packet or not.
        if ipv4.ipv4 not in pkt or udp.udp not in pkt:
            return

        udp_hdr = pkt.get_protocols(udp.udp)[0]
        if udp_hdr.dst_port != BFD_CONTROL_UDP_PORT:
            return

        # Parse BFD packet here.
        self.recv_bfd_pkt(datapath, in_port, msg.data) 
开发者ID:lagopus,项目名称:ryu-lagopus-ext,代码行数:47,代码来源:bfdlib.py

示例14: packet_in_handler

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REPLY [as 别名]
def packet_in_handler(self, ev):
        msg = ev.msg
        dp = msg.datapath

        pkt = packet.Packet(array.array('B', msg.data))
        p_arp = self._find_protocol(pkt, "arp")
        p_icmp = self._find_protocol(pkt, "icmp")
        p_ipv4 = self._find_protocol(pkt, "ipv4")

        if p_arp:
            src_ip = str(netaddr.IPAddress(p_arp.src_ip))
            dst_ip = str(netaddr.IPAddress(p_arp.dst_ip))
            if p_arp.opcode == arp.ARP_REQUEST:
                LOG.debug("--- PacketIn: ARP_Request: %s->%s", src_ip, dst_ip)
                if p_arp.dst_ip == self.RYU_IP:
                    LOG.debug("--- send Pkt: ARP_Reply")
                    data = self._arp_reply()
                    self._send_msg(dp, data)
                elif p_arp.dst_ip == self.HOST_IP:
                    LOG.debug("    PacketIn: GARP")
                    LOG.debug("--- send Pkt: ARP_Request")
                    data = self._arp_request()
                    self._send_msg(dp, data)
            elif p_arp.opcode == arp.ARP_REPLY:
                LOG.debug("--- PacketIn: ARP_Reply: %s->%s", src_ip, dst_ip)
                LOG.debug("--- send Pkt: Echo_Request")
                echo = icmp.echo(id_=66, seq=1)
                data = self._echo_request(echo)
                self._send_msg(dp, data)

        if p_icmp:
            src = str(netaddr.IPAddress(p_ipv4.src))
            dst = str(netaddr.IPAddress(p_ipv4.dst))
            if p_icmp.type == icmp.ICMP_ECHO_REQUEST:
                LOG.debug("--- PacketIn: Echo_Request: %s->%s", src, dst)
                if p_ipv4.dst == self.RYU_IP:
                    LOG.debug("--- send Pkt: Echo_Reply")
                    echo = p_icmp.data
                    echo.data = bytearray(echo.data)
                    data = self._echo_reply(echo)
                    self._send_msg(dp, data)
            elif p_icmp.type == icmp.ICMP_ECHO_REPLY:
                LOG.debug("--- PacketIn: Echo_Reply: %s->%s", src, dst) 
开发者ID:lagopus,项目名称:ryu-lagopus-ext,代码行数:45,代码来源:test_arp.py


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