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


Python arp.ARP_REQUEST属性代码示例

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


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

示例1: arp_parse

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REQUEST [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_REQUEST [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_REQUEST [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_REQUEST [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_REQUEST [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_for_ip_gw

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REQUEST [as 别名]
def arp_for_ip_gw(self, ip_gw, controller_ip, vlan, ports):
        flowmods = []
        if ports:
            self.logger.info('Resolving %s', ip_gw)
            arp_pkt = arp.arp(
                opcode=arp.ARP_REQUEST, src_mac=self.FAUCET_MAC,
                src_ip=str(controller_ip.ip), dst_mac=mac.DONTCARE_STR,
                dst_ip=str(ip_gw))
            port_num = ports[0].number
            pkt = self.build_ethernet_pkt(
                mac.BROADCAST_STR, port_num, vlan, ether.ETH_TYPE_ARP)
            pkt.add_protocol(arp_pkt)
            pkt.serialize()
            for port in ports:
                flowmods.append(self.valve_packetout(port.number, pkt.data))
        return flowmods 
开发者ID:onfsdn,项目名称:noc,代码行数:18,代码来源:valve.py

示例7: send_arp_request

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REQUEST [as 别名]
def send_arp_request(self, src_ip, dst_ip, in_port=None):
        # Send ARP request from all ports.
        for send_port in self.port_data.values():
            if in_port is None or in_port != send_port.port_no:
                src_mac = send_port.mac
                dst_mac = mac_lib.BROADCAST_STR
                arp_target_mac = mac_lib.DONTCARE_STR
                inport = self.ofctl.dp.ofproto.OFPP_CONTROLLER
                output = send_port.port_no
                self.ofctl.send_arp(arp.ARP_REQUEST, self.vlan_id,
                                    src_mac, dst_mac, src_ip, dst_ip,
                                    arp_target_mac, inport, output) 
开发者ID:PacktPublishing,项目名称:Mastering-Python-Networking,代码行数:14,代码来源:chapter13_router_1.py

示例8: cmd_who_has

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REQUEST [as 别名]
def cmd_who_has(self, *args):

        if len(args) == 0:
            return "Usage: arp-proxy:who-has [IP]"

        arp_req = packet.Packet()
        arp_req.add_protocol(
            ethernet.ethernet(
                ethertype=ether_types.ETH_TYPE_ARP,
                src=fake_mac,
                dst='ff:ff:ff:ff:ff:ff'
            )
        )
        arp_req.add_protocol(
            arp.arp(
                opcode=arp.ARP_REQUEST,
                src_ip=FAKE_IP,
                src_mac=FAKE_MAC,
                dst_ip=src_ip,
            )
        )
        arp_req.serialize()

        for port in self.fwd.get_all_edge_port():
            datapath = self.fwd.get_datapath(port.dpid)
            port_no = port.port_no
            ofproto = datapath.ofproto
            parser = datapath.ofproto_parser
            actions = [parser.OFPActionOutput(port_no)]
            out = parser.OFPPacketOut(
                datapath=datapath,
                buffer_id=ofproto.OFP_NO_BUFFER,
                in_port=ofproto.OFPP_CONTROLLER,
                actions=actions, data=arp_req.data)
            datapath.send_msg(out)

        return "Done" 
开发者ID:sdnds-tw,项目名称:Ryu-SDN-IP,代码行数:39,代码来源:arp_proxy.py

示例9: _garp

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

示例10: _garp_packet

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REQUEST [as 别名]
def _garp_packet(self, ip_address):
        # prepare garp packet
        src_mac = vrrp.vrrp_ipv4_src_mac_address(self.config.vrid)
        e = ethernet.ethernet(mac_lib.BROADCAST_STR, src_mac,
                              ether.ETH_TYPE_ARP)
        a = arp.arp_ip(arp.ARP_REQUEST, src_mac, ip_address,
                       mac_lib.DONTCARE_STR, ip_address)

        p = packet.Packet()
        p.add_protocol(e)
        utils.may_add_vlan(p, self.interface.vlan_id)
        p.add_protocol(a)
        p.serialize()
        return p 
开发者ID:lagopus,项目名称:ryu-lagopus-ext,代码行数:16,代码来源:sample_router.py

示例11: _arp_process

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REQUEST [as 别名]
def _arp_process(self, data):
        dst_mac = vrrp.vrrp_ipv4_src_mac_address(self.config.vrid)
        arp_sha = None
        arp_spa = None
        arp_tpa = None

        p = packet.Packet(data)
        for proto in p.protocols:
            if isinstance(proto, ethernet.ethernet):
                if proto.dst not in (mac_lib.BROADCAST_STR, dst_mac):
                    return None
                ethertype = proto.ethertype
                if not ((self.interface.vlan_id is None and
                         ethertype == ether.ETH_TYPE_ARP) or
                        (self.interface.vlan_id is not None and
                         ethertype == ether.ETH_TYPE_8021Q)):
                    return None
            elif isinstance(proto, vlan.vlan):
                if (proto.vid != self.interface.vlan_id or
                        proto.ethertype != ether.ETH_TYPE_ARP):
                    return None
            elif isinstance(proto, arp.arp):
                if (proto.hwtype != arp.ARP_HW_TYPE_ETHERNET or
                    proto.proto != ether.ETH_TYPE_IP or
                    proto.hlen != 6 or proto.plen != 4 or
                    proto.opcode != arp.ARP_REQUEST or
                        proto.dst_mac != dst_mac):
                    return None
                arp_sha = proto.src_mac
                arp_spa = proto.src_ip
                arp_tpa = proto.dst_ip
                break

        if arp_sha is None or arp_spa is None or arp_tpa is None:
            self.logger.debug('malformed arp request? arp_sha %s arp_spa %s',
                              arp_sha, arp_spa)
            return None

        self._arp_reply_packet(arp_sha, arp_spa, arp_tpa) 
开发者ID:lagopus,项目名称:ryu-lagopus-ext,代码行数:41,代码来源:sample_router.py

示例12: _arp_match

# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import ARP_REQUEST [as 别名]
def _arp_match(self, dp):
        kwargs = {}
        kwargs['in_port'] = self.interface.port_no
        kwargs['eth_dst'] = mac_lib.BROADCAST_STR
        kwargs['eth_type'] = ether.ETH_TYPE_ARP
        if self.interface.vlan_id is not None:
            kwargs['vlan_vid'] = self.interface.vlan_id
        kwargs['arp_op'] = arp.ARP_REQUEST
        kwargs['arp_tpa'] = vrrp.vrrp_ipv4_src_mac_address(self.config.vrid)
        return dp.ofproto_parser.OFPMatch(**kwargs) 
开发者ID:lagopus,项目名称:ryu-lagopus-ext,代码行数:12,代码来源:sample_router.py

示例13: _handle_arp

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

示例14: _handle_arp

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

示例15: _add_arp_reply_flow

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


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