本文整理汇总了Python中ryu.lib.packet.arp.arp方法的典型用法代码示例。如果您正苦于以下问题:Python arp.arp方法的具体用法?Python arp.arp怎么用?Python arp.arp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ryu.lib.packet.arp
的用法示例。
在下文中一共展示了arp.arp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: arp_for_ip_gw
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [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
示例2: __init__
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [as 别名]
def __init__(self, *args, **kwargs):
super(ArpProxy, self).__init__(*args, **kwargs)
self.fwd = kwargs['fwd']
self.cfg_mgr = SDNIPConfigManager()
self.arp_table = {}
if CONF.static_arp_table is not None:
# load static arp table
static_arp_table = json.load(open(CONF.static_arp_table, "r"))
for record in static_arp_table:
self.arp_table.setdefault(record['ip'], record['mac'])
if with_dk:
dk_plugin.DynamicLoader.register_custom_cmd('arp-proxy:table', self.cmd_dump_arp_table)
dk_plugin.DynamicLoader.register_custom_cmd('arp-proxy:reload', self.cmd_reload_static)
dk_plugin.DynamicLoader.register_custom_cmd('arp-proxy:who-has', self.cmd_who_has)
示例3: __init__
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [as 别名]
def __init__(self, *args, **kwargs):
super(ArpProxy, self).__init__(*args, **kwargs)
self.fwd = kwargs['fwd']
self.cfg_mgr = SDNIPConfigManager()
self.arp_table = {}
static_arp_table = [
{"ip": "10.0.0.1", "mac": "00:00:00:00:00:01"},
{"ip": "10.0.0.2", "mac": "00:00:00:00:00:02"}
]
for record in static_arp_table:
self.arp_table.setdefault(record['ip'], record['mac'])
if with_dk:
dk_plugin.DynamicLoader.register_custom_cmd('arp-proxy:table', self.cmd_dump_arp_table)
dk_plugin.DynamicLoader.register_custom_cmd('arp-proxy:reload', self.cmd_reload_static)
dk_plugin.DynamicLoader.register_custom_cmd('arp-proxy:who-has', self.cmd_who_has)
示例4: _packet_in_handler
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [as 别名]
def _packet_in_handler(self, ev):
"""
Handle the packet_in packet, and register the access info.
"""
msg = ev.msg
datapath = msg.datapath
in_port = msg.match['in_port']
pkt = packet.Packet(msg.data)
arp_pkt = pkt.get_protocol(arp.arp)
ip_pkt = pkt.get_protocol(ipv4.ipv4)
if arp_pkt:
arp_src_ip = arp_pkt.src_ip
mac = arp_pkt.src_mac
# Record the access infomation.
self.register_access_info(datapath.id, in_port, arp_src_ip, mac)
elif ip_pkt:
ip_src_ip = ip_pkt.src
eth = pkt.get_protocols(ethernet.ethernet)[0]
mac = eth.src
# Record the access infomation.
self.register_access_info(datapath.id, in_port, ip_src_ip, mac)
else:
pass
示例5: _packet_in_handler
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [as 别名]
def _packet_in_handler(self, ev):
'''
In packet_in handler, we need to learn access_table by ARP and IP packets.
'''
msg = ev.msg
pkt = packet.Packet(msg.data)
arp_pkt = pkt.get_protocol(arp.arp)
ip_pkt = pkt.get_protocol(ipv4.ipv4)
if isinstance(arp_pkt, arp.arp):
self.logger.debug("ARP processing")
self.arp_forwarding(msg, arp_pkt.src_ip, arp_pkt.dst_ip)
if isinstance(ip_pkt, ipv4.ipv4):
self.logger.debug("IPV4 processing")
if len(pkt.get_protocols(ethernet.ethernet)):
eth_type = pkt.get_protocols(ethernet.ethernet)[0].ethertype
self.shortest_forwarding(msg, eth_type, ip_pkt.src, ip_pkt.dst)
示例6: arp_parse
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [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
示例7: _build_arp
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [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
示例8: _arp_reply_packet
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [as 别名]
def _arp_reply_packet(self, arp_req_sha, arp_req_spa, arp_req_tpa):
if not (arp_req_tpa in self.config.ip_addresses or
arp_req_tpa == self.config.primary_ip_address):
return None
src_mac = vrrp.vrrp_ipv4_src_mac_address(self.config.vrid)
e = ethernet.ethernet(arp_req_sha, src_mac, ether.ETH_TYPE_ARP)
a = arp.arp_ip(arp.ARP_REPLY, src_mac, arp_req_tpa,
arp_req_sha, arp_req_spa)
p = packet.Packet()
p.add_protocol(e)
utils.may_add_vlan(p, self.interface.vlan_id)
p.add_protocol(a)
p.serialize()
self._transmit(p.data)
示例9: _packet_in_handler
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [as 别名]
def _packet_in_handler(self, ev):
'''
In packet_in handler, we need to learn access_table by ARP.
Therefore, the first packet from UNKOWN host MUST be ARP.
'''
receive_time = time.time()
msg = ev.msg
datapath = msg.datapath
in_port = msg.match['in_port']
pkt = packet.Packet(msg.data)
arp_pkt = pkt.get_protocol(arp.arp)
ip_pkt = pkt.get_protocol(ipv4.ipv4)
eth_type = pkt.get_protocols(ethernet.ethernet)[0].ethertype
if eth_type == 0x07c3:
result_list = pkt[-1].split('#')
#self.total_time = receive_time-float(result_list[1])
self.total_time -= receive_time
self.packets_NO -= 1
print ("received!")
示例10: _packet_in_handler
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [as 别名]
def _packet_in_handler(self, ev):
'''
In packet_in handler, we need to learn access_table by ARP.
Therefore, the first packet from UNKOWN host MUST be ARP.
'''
msg = ev.msg
datapath = msg.datapath
in_port = msg.match['in_port']
pkt = packet.Packet(msg.data)
arp_pkt = pkt.get_protocol(arp.arp)
ip_pkt = pkt.get_protocol(ipv4.ipv4)
eth_type = pkt.get_protocols(ethernet.ethernet)[0].ethertype
if eth_type == 0x07c3:
print "received!"
if isinstance(arp_pkt, arp.arp):
self.logger.debug("ARP processing")
self.arp_forwarding(msg, arp_pkt.src_ip, arp_pkt.dst_ip)
if isinstance(ip_pkt, ipv4.ipv4):
self.logger.debug("IPV4 processing")
if len(pkt.get_protocols(ethernet.ethernet)):
#eth_type = pkt.get_protocols(ethernet.ethernet)[0].ethertype
self.shortest_forwarding(msg, eth_type, ip_pkt.src, ip_pkt.dst)
示例11: _packet_in_handler
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [as 别名]
def _packet_in_handler(self, ev):
msg = ev.msg
datapath = msg.datapath
parser = datapath.ofproto_parser
in_port = msg.match['in_port']
pkt = packet.Packet(msg.data)
eth_type = pkt.get_protocols(ethernet.ethernet)[0].ethertype
arp_pkt = pkt.get_protocol(arp.arp)
ip_pkt = pkt.get_protocol(ipv4.ipv4)
if arp_pkt:
arp_src_ip = arp_pkt.src_ip
arp_dst_ip = arp_pkt.dst_ip
mac = arp_pkt.src_mac
# record the access info
self.register_access_info(datapath.id, in_port, arp_src_ip, mac)
# show topo
示例12: receive_arp
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [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
示例13: _handle_arp
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [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)
示例14: arp_parse
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [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
示例15: send_arp_request
# 需要导入模块: from ryu.lib.packet import arp [as 别名]
# 或者: from ryu.lib.packet.arp import arp [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)