本文整理汇总了Python中ryu.lib.packet.packet.Packet类的典型用法代码示例。如果您正苦于以下问题:Python Packet类的具体用法?Python Packet怎么用?Python Packet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Packet类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: packetIn_handler
def packetIn_handler(self,event):
msg = event.msg
data = msg.data
datapath = msg.datapath
dapid = datapath.id
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
in_port = msg.match['in_port']
pkt = Packet(data)
eth = pkt.get_protocol(ethernet)
eth_src = eth.src
eth_dst = eth.dst
self.mac_to_port.setdefault(datapath.id,{})
self.mac_to_port[datapath.id].setdefault(eth_src,in_port)
#self.mac_to_port[datapath.id][eth_src] = in_port
allPkts = dict((p.protocol_name,p) for p in pkt.protocols)
print("packet in %s %s"%(str(eth_src),str(eth_dst)))
if eth_dst in self.mac_to_port[datapath.id]:
out_port = self.mac_to_port[datapath.id][eth_dst]
else:
out_port = ofproto.OFPP_FLOOD
actions = [parser.OFPActionOutput(out_port)]
pktout_msg = parser.OFPPacketOut(datapath=datapath,buffer_id=ofproto.OFP_NO_BUFFER,
in_port=in_port,actions=actions,data=msg.data)
datapath.send_msg(pktout_msg)
开发者ID:znbupt,项目名称:MyRYUApp,代码行数:31,代码来源:dealWithLoop_01.py
示例2: test_Packet_in_3_arpReply2
def test_Packet_in_3_arpReply2(self):
print "*** Case3: HOST1のMAC学習済の時、HOST2からARP Replyを受信 ***"
sr = SimpleForward()
sr.HOST_MACADDR1 = HOST_MACADDR1
sr.HOST_MACADDR2 = HOST_MACADDR2
dstMac = ROUTER_MACADDR2
srcMac = HOST_MACADDR2
srcIp = HOST_IPADDR2
dstIp = ROUTER_IPADDR2
targetMac = dstMac
targetIp = dstIp
datapath = _Datapath()
e = ethernet(dstMac, srcMac, ether.ETH_TYPE_ARP)
a = arp(1, 0x0800, 6, 4, 2, srcMac, srcIp, targetMac, targetIp)
p = Packet()
p.add_protocol(e)
p.add_protocol(a)
p.serialize()
packetIn = OFPPacketIn(datapath, match=OFPMatch(in_port=2), data=buffer(p.data))
ev = ofp_event.EventOFPPacketIn(packetIn)
result = sr.packet_in_handler(ev)
self.assertEqual(result, 0)
print ""
开发者ID:TakeshiTseng,项目名称:simpleRouter,代码行数:29,代码来源:test_SimpleForward.py
示例3: _packet_in_handler
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
开发者ID:ShuaiZhao,项目名称:Ryu-SDN-Codes,代码行数:60,代码来源:my_arp_v2_copy.py
示例4: 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
示例5: test_Packet_in_1_arpRequest
def test_Packet_in_1_arpRequest(self):
print "*** Case1: HOST1からARP Request受信 ***"
sr = SimpleForward()
dstMac = "ff:ff:ff:ff:ff:ff"
srcMac = HOST_MACADDR1
srcIp = HOST_IPADDR1
dstIp = ROUTER_IPADDR1
targetMac = dstMac
targetIp = dstIp
datapath = _Datapath()
e = ethernet(dstMac, srcMac, ether.ETH_TYPE_ARP)
a = arp(1, 0x0800, 6, 4, 1, srcMac, srcIp, targetMac, targetIp)
p = Packet()
p.add_protocol(e)
p.add_protocol(a)
p.serialize()
packetIn = OFPPacketIn(datapath, match=OFPMatch(in_port=1), data=buffer(p.data))
ev = ofp_event.EventOFPPacketIn(packetIn)
result = sr.packet_in_handler(ev)
self.assertEqual(result, 0)
print ""
开发者ID:TakeshiTseng,项目名称:simpleRouter,代码行数:26,代码来源:test_SimpleForward.py
示例6: packet_In_handler
def packet_In_handler(self, event):
msg = event.msg
datapath = msg.datapath
if datapath.id not in self.allDatapath:
self.allDatapath[datapath.id] = datapath
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
match = msg.match
data = msg.data
in_port = match["in_port"]
pkt = Packet(data)
eth = pkt.get_protocol(ethernet)
src = eth.src
dst = eth.dst
self.mac_to_port.setdefault(datapath.id, {})
self.mac_to_port[datapath.id][src] = in_port
if dst in self.mac_to_port[datapath.id]:
out_port = self.mac_to_port[datapath.id][dst]
else:
out_port = ofproto.OFPP_FLOOD
actions = [parser.OFPActionOutput(out_port)]
match = parser.OFPMatch(in_port=in_port, eth_src=src, eth_dst=dst)
instructions = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, actions=actions)]
self.addFlow(datapath=datapath, priority=1, match=match, instructions=instructions)
out_msg = parser.OFPPacketOut(
datapath=datapath, buffer_id=msg.buffer_id, in_port=in_port, actions=actions, data=None
)
datapath.send_msg(out_msg)
开发者ID:znbupt,项目名称:MyRYUApp,代码行数:28,代码来源:myFlowTest.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: 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
示例9: packet_in_handler
def packet_in_handler(self, ev):
msg = ev.msg
pkt = Packet(msg.data)
dp = msg.datapath
in_port = msg.match['in_port']
ofp = dp.ofproto
ofp_parser = dp.ofproto_parser
#pdb.set_trace()
actions = []
#dp.send_msg(out)
ip = pkt.get_protocol(ipv4.ipv4)
print ip
if ip:
print ip
#actions.append(ofp.OFPActionDecNwTtl())
actions.append(ofp_parser.OFPActionOutput(ofp.OFPP_FLOOD))
out = ofp_parser.OFPPacketOut(
datapath=dp, buffer_id=msg.buffer_id, in_port=in_port,
actions=actions)
dp.send_msg(out)
开发者ID:arthurandrade,项目名称:Trabredes,代码行数:31,代码来源:setarIP.py
示例10: send_arp
def send_arp(self, datapath, opcode, srcMac, srcIp, dstMac, dstIp, outPort, RouteDist=None):
if opcode == 1:
self.portInfo[outPort] = PortTable(outPort, srcIp, srcMac, RouteDist)
targetMac = "00:00:00:00:00:00"
targetIp = dstIp
elif opcode == 2:
targetMac = dstMac
targetIp = dstIp
e = ethernet(dstMac, srcMac, ether.ETH_TYPE_ARP)
a = arp(1, 0x0800, 6, 4, opcode, srcMac, srcIp, targetMac, targetIp)
p = Packet()
p.add_protocol(e)
p.add_protocol(a)
p.serialize()
actions = [datapath.ofproto_parser.OFPActionOutput(outPort, 0)]
out = datapath.ofproto_parser.OFPPacketOut(
datapath=datapath,
buffer_id=0xffffffff,
in_port=datapath.ofproto.OFPP_CONTROLLER,
actions=actions,
data=p.data)
datapath.send_msg(out)
return 0
开发者ID:amalwilson,项目名称:simpleRouter,代码行数:26,代码来源:simpleRouter.py
示例11: _packet_in_handler
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
开发者ID:ShuaiZhao,项目名称:Ryu-SDN-Codes,代码行数:29,代码来源:my_arp_v2.py
示例12: _packet_in_handler
def _packet_in_handler(self, ev):
"""Handle packet_in events."""
if not self.link_discovery:
return
msg = ev.msg
in_port = msg.match['in_port']
packet = Packet(msg.data)
efm = packet.next()
if efm.ethertype == ether.ETH_TYPE_ARP:
self.send_event_to_observers(event.EventArpReceived(ev))
try:
src_dpid, src_port_no = LLDPPacket.lldp_parse(msg.data)
except LLDPPacket.LLDPUnknownFormat as e:
# This handler can receive all the packtes which can be
# not-LLDP packet. Ignore it silently
return
else:
dst_dpid = msg.datapath.id
dst_port_no = in_port
src = self._get_port(src_dpid, src_port_no)
if not src or src.dpid == dst_dpid:
return
dst = self._get_port(dst_dpid, dst_port_no)
if not dst:
return
old_peer = self.links.get_peer(src)
#LOG.debug("Packet-In")
#LOG.debug(" src=%s", src)
#LOG.debug(" dst=%s", dst)
#LOG.debug(" old_peer=%s", old_peer)
if old_peer and old_peer != dst:
old_link = Link(src, old_peer)
self.send_event_to_observers(event.EventLinkDelete(old_link))
link = Link(src, dst)
if not link in self.links:
self.send_event_to_observers(event.EventLinkAdd(link))
if not self.links.update_link(src, dst):
# reverse link is not detected yet.
# So schedule the check early because it's very likely it's up
try:
self.ports.lldp_received(dst)
except KeyError as e:
# There are races between EventOFPPacketIn and
# EventDPPortAdd. So packet-in event can happend before
# port add event. In that case key error can happend.
# LOG.debug('lldp_received: KeyError %s', e)
pass
else:
self.ports.move_front(dst)
self.lldp_event.set()
开发者ID:shelfin,项目名称:CloudySwitch,代码行数:56,代码来源:switches_v1_3.py
示例13: _build_vlan
def _build_vlan(self):
src_mac = mac.haddr_to_bin('00:07:0d:af:f4:54')
dst_mac = mac.haddr_to_bin('00:00:00:00:00:00')
ethertype = ether.ETH_TYPE_8021Q
e = ethernet(dst_mac, src_mac, ethertype)
version = 4
header_length = 20
tos = 0
total_length = 24
identification = 0x8a5d
flags = 0
offset = 1480
ttl = 64
proto = inet.IPPROTO_ICMP
csum = 0xa7f2
src = int(netaddr.IPAddress('131.151.32.21'))
dst = int(netaddr.IPAddress('131.151.32.129'))
option = 'TEST'
ip = ipv4(version, header_length, tos, total_length, identification,
flags, offset, ttl, proto, csum, src, dst, option)
p = Packet()
p.add_protocol(e)
p.add_protocol(self.v)
p.add_protocol(ip)
p.serialize()
return p
开发者ID:09zwcbupt,项目名称:ryu,代码行数:30,代码来源:test_vlan.py
示例14: test_Packet_in_2_icmpEcho1
def test_Packet_in_2_icmpEcho1(self):
print "*** Case2: HOST2のMAC未学習の時、HOST1からICMP Echoを受信 ***"
sr = SimpleForward()
dstMac = ROUTER_MACADDR1
srcMac = HOST_MACADDR1
srcIp = HOST_IPADDR1
dstIp = HOST_IPADDR2
targetMac = dstMac
targetIp = dstIp
ttl = 64
datapath = _Datapath()
e = ethernet(dstMac, srcMac, ether.ETH_TYPE_IP)
iph = ipv4(4, 5, 0, 0, 0, 2, 0, ttl, 1, 0, srcIp, dstIp)
echo = icmp.echo(1, 1, 'unit test')
icmph = icmp.icmp(8, 0, 0, echo)
p = Packet()
p.add_protocol(e)
p.add_protocol(iph)
p.add_protocol(icmph)
p.serialize()
packetIn = OFPPacketIn(datapath, match=OFPMatch(in_port=1), data=buffer(p.data))
ev = ofp_event.EventOFPPacketIn(packetIn)
result = sr.packet_in_handler(ev)
self.assertEqual(result, 1)
print ""
开发者ID:TakeshiTseng,项目名称:simpleRouter,代码行数:32,代码来源:test_SimpleForward.py
示例15: enviar_arp
def enviar_arp(self, mac_origen, port, next_hop, datapath, msg, nat=None, puertoNat=None):
e = ethernet.ethernet(src=mac_origen, ethertype=ether.ETH_TYPE_ARP)
a = arp.arp(opcode=arp.ARP_REQUEST,
src_ip=self.ports_to_ips[port-1][0],
src_mac=mac_origen,
dst_ip=next_hop)
#puerto = mac_origen
p = Packet()
p.add_protocol(e)
p.add_protocol(a)
self.insertar_en_cola(ip=next_hop, puerto=port, msg=msg, nat=nat, puertoNat=puertoNat)
self.send_packet(datapath=datapath, port=port, packet=p)
开发者ID:Madh93,项目名称:NatRouter,代码行数:12,代码来源:PAT.py
示例16: packet_in_handler
def packet_in_handler(self, ev):
msg = ev.msg
datapath = msg.datapath
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
pkt = Packet(msg.data)
pkt_udp = pkt.get_protocol(udp.udp)
pkt_tcp = pkt.get_protocol(tcp.tcp)
header_list = dict((p.protocol_name, p)
for p in pkt.protocols if type(p) != str)
self.logger.info(header_list)
if pkt_udp:
src_port = pkt_udp.src_port
dst_port = pkt_udp.dst_port
elif pkt_tcp:
src_port = pkt_tcp.src_port
dst_port = pkt_tcp.dst_port
for ipproto in [6,17]:
mod_flow_entry(datapath,
{'priority' : 100,
'table_id' : 0,
'match' : {'tp_src': src_port,
'dl_type': 2048,
'ip_proto': ipproto},
'actions' :[{'type': 'WRITE_METADATA',
'metadata': src_port << 16,
'metadata_mask' : 4294901760},
{'type': 'GOTO_TABLE',
'table_id' : 1}]},
ofproto.OFPFC_ADD)
mod_flow_entry(datapath,
{'priority' : 100,
'table_id' : 1,
'match' : {'tp_dst': dst_port,
'dl_type': 2048,
'ip_proto': ipproto},
'actions' :[{'type': 'WRITE_METADATA',
'metadata': dst_port,
'metadata_mask': 65535},
{'type' : 'GOTO_TABLE',
'table_id' : 2}]},
ofproto.OFPFC_ADD)
self.packet_out(datapath, pkt)
开发者ID:hibitomo,项目名称:lagofirewall,代码行数:48,代码来源:lagofirewall.py
示例17: 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)
#print packet.get_protocol(ipv4.ipv4)
print "LLEGÓ UN PAQUETE IP"
if ipPacket.dst == self.ports_to_ips[0][0]: #Si va destinado al router
print "VA DESTINADO AL ROUTER"
if ipPacket.proto == inet.IPPROTO_ICMP:
print "Y ES 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
print "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
print "¿Está dentro de la tabla ", next_hop, " ?"
if next_hop in self.ipToMac.keys(): #Si está dentro de la tabla de ips y macs se envía.
print "ESTÁ DENTRO DE LA TABLA##################################################"
print "ipToMac[next_hop] = ", self.ipToMac[next_hop]
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, self.ipToMac[next_hop], port)
else: #Si no está dentro de la tabla se construye un paquete ARP para averiguar su MAC
print "NO ESTÁ DENTRO DE LA TABLA"
print "---- NEXT_HOP -----", next_hop
e = ethernet.ethernet(#dst=etherFrame.dst,
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)]
#def send_packet(self, datapath, port, packet):
print "llegó por el PUERTO: ", inPort, "Sale por el puerto: ", port
self.send_packet(datapath=datapath, port=port, packet=p)
开发者ID:Madh93,项目名称:NatRouter,代码行数:47,代码来源:router.py
示例18: _packet_in_handler
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
开发者ID:ShuaiZhao,项目名称:Ryu-SDN-Codes,代码行数:46,代码来源:myarp_v6.py
示例19: test_Packet_in
def test_Packet_in(self):
sa = SimpleArp()
datapath = _Datapath()
e = ethernet.ethernet(dstMac, srcMac, ether.ETH_TYPE_ARP)
a = arp(1, 0x0800, 6, 4, 1, srcMac, srcIp, targetMac, dstIp)
p = Packet()
p.add_protocol(e)
p.add_protocol(a)
p.serialize()
packetIn = OFPPacketIn(datapath, match=OFPMatch(in_port=1), data=buffer(p.data))
ev = ofp_event.EventOFPPacketIn(packetIn)
result = sa.packet_in_handler(ev)
self.assertEqual(result, 0)
开发者ID:TakeshiTseng,项目名称:simpleRouter,代码行数:17,代码来源:test_SimpleArp.py
示例20: send_icmp
def send_icmp(self, datapath, etherFrame,ipPacket, icmpPacket,inPort):
e = ethernet(dst=etherFrame.src ,
src=etherFrame.dst,
ethertype=ether.ETH_TYPE_IP)
a = ipv4(version=ipPacket.version, header_length=ipPacket.header_length, tos=ipPacket.tos,
total_length=ipPacket.total_length, identification=ipPacket.identification, flags=ipPacket.flags,
offset=ipPacket.offset, ttl=ipPacket.ttl, proto=ipPacket.proto, csum=ipPacket.csum,
src=ipPacket.dst,
dst= ipPacket.src,
option=None)
b = icmp( type_=ICMP_ECHO_REPLY, code=icmpPacket.code, csum=icmpPacket.csum, data=icmpPacket.data)
p = Packet()
p.add_protocol(e)
p.add_protocol(a)
p.add_protocol(b)
p.serialize()
actions = [datapath.ofproto_parser.OFPActionOutput(inPort, 0)]
out = datapath.ofproto_parser.OFPPacketOut(
datapath=datapath,
buffer_id=0xffffffff,
in_port=datapath.ofproto.OFPP_CONTROLLER,
actions=actions,
data=p.data)
datapath.send_msg(out)
开发者ID:ljyfree,项目名称:ryu,代码行数:25,代码来源:simple_arp_icmp.py
注:本文中的ryu.lib.packet.packet.Packet类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论