本文整理汇总了Python中ryu.lib.packet.packet.Packet.serialize方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.serialize方法的具体用法?Python Packet.serialize怎么用?Python Packet.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ryu.lib.packet.packet.Packet
的用法示例。
在下文中一共展示了Packet.serialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_Packet_in_1_arpRequest
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
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 ""
示例2: test_Packet_in_2_icmpEcho1
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
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 ""
示例3: test_Packet_in_3_arpReply2
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
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 ""
示例4: test_Packet_in_4_icmpEcho2
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
def test_Packet_in_4_icmpEcho2(self):
print "*** Case4: HOST2からHOST1以外の宛先IPへのIPパケットを受信 ***"
sr = SimpleForward()
sr.HOST_MACADDR1 = HOST_MACADDR1
sr.HOST_MACADDR2 = HOST_MACADDR2
dstMac = ROUTER_MACADDR2
srcMac = HOST_MACADDR2
srcIp = HOST_IPADDR2
dstIp = "91.189.89.22"
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)
p = Packet()
p.add_protocol(e)
p.add_protocol(iph)
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, 1)
print ""
示例5: send_arp
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
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
示例6: _build_vlan
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
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
示例7: send_icmp
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
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)
示例8: _build_lacp
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
def _build_lacp(self):
ethertype = ether.ETH_TYPE_SLOW
dst = SLOW_PROTOCOL_MULTICAST
e = ethernet(dst, self.actor_system, ethertype)
p = Packet()
p.add_protocol(e)
p.add_protocol(self.l)
p.serialize()
return p
示例9: _build_arp
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
def _build_arp(self, vlan_enabled):
if vlan_enabled is True:
ethertype = ether.ETH_TYPE_8021Q
v = vlan(1, 1, 3, ether.ETH_TYPE_ARP)
else:
ethertype = ether.ETH_TYPE_ARP
e = ethernet(self.dst_mac, self.src_mac, ethertype)
p = Packet()
p.add_protocol(e)
if vlan_enabled is True:
p.add_protocol(v)
p.add_protocol(self.a)
p.serialize()
return p
示例10: send_icmp
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
def send_icmp(self, datapath, srcMac, srcIp, dstMac, dstIp, outPort, seq, data, id=1, type=8, ttl=64):
e = ethernet.ethernet(dstMac, srcMac, ether.ETH_TYPE_IP) #Construye el protocolo ethernet
iph = ipv4.ipv4(4, 5, 0, 0, 0, 2, 0, ttl, 1, 0, srcIp, dstIp) #Construye la parte del protocolo IP
echo = icmp.echo(id, seq, data) #Construye la parte del echo que se añadirá al protocolo icmp
icmph = icmp.icmp(type, 0, 0, echo) #Construye la parte del icmp
p = Packet() #Crea el paquete
p.add_protocol(e) #Añade el protocolo ethernet
p.add_protocol(iph) #Añade el protocolo ip
p.add_protocol(icmph) #Añade el protocolo icmp
p.serialize() #Serializa todo
actions = [datapath.ofproto_parser.OFPActionOutput(outPort, 0)] #Enviar por el puerto outPort
#Mensaje a enviar
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) #Enviar mensaje
示例11: test_Packet_in
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
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)
示例12: _build_igmp
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
def _build_igmp(self):
dl_dst = "11:22:33:44:55:66"
dl_src = "aa:bb:cc:dd:ee:ff"
dl_type = ether.ETH_TYPE_IP
e = ethernet(dl_dst, dl_src, dl_type)
total_length = 20 + igmp._MIN_LEN
nw_proto = inet.IPPROTO_IGMP
nw_dst = "11.22.33.44"
nw_src = "55.66.77.88"
i = ipv4(total_length=total_length, src=nw_src, dst=nw_dst, proto=nw_proto)
p = Packet()
p.add_protocol(e)
p.add_protocol(i)
p.add_protocol(self.g)
p.serialize()
return p
示例13: _build_igmp
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
def _build_igmp(self):
dl_dst = '11:22:33:44:55:66'
dl_src = 'aa:bb:cc:dd:ee:ff'
dl_type = ether.ETH_TYPE_IP
e = ethernet(dl_dst, dl_src, dl_type)
total_length = len(ipv4()) + len(self.g)
nw_proto = inet.IPPROTO_IGMP
nw_dst = '11.22.33.44'
nw_src = '55.66.77.88'
i = ipv4(total_length=total_length, src=nw_src, dst=nw_dst,
proto=nw_proto, ttl=1)
p = Packet()
p.add_protocol(e)
p.add_protocol(i)
p.add_protocol(self.g)
p.serialize()
return p
示例14: send_icmp
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
def send_icmp(self, datapath, srcMac, srcIp, dstMac, dstIp, outPort, seq, data, id=1, type=8, ttl=64):
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(id, seq, data)
icmph = icmp.icmp(type, 0, 0, echo)
p = Packet()
p.add_protocol(e)
p.add_protocol(iph)
p.add_protocol(icmph)
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
示例15: _build_svlan
# 需要导入模块: from ryu.lib.packet.packet import Packet [as 别名]
# 或者: from ryu.lib.packet.packet.Packet import serialize [as 别名]
def _build_svlan(self):
src_mac = '00:07:0d:af:f4:54'
dst_mac = '00:00:00:00:00:00'
ethertype = ether.ETH_TYPE_8021AD
e = ethernet(dst_mac, src_mac, ethertype)
pcp = 0
cfi = 0
vid = 32
tci = pcp << 15 | cfi << 12 | vid
ethertype = ether.ETH_TYPE_IP
v = vlan(pcp, cfi, vid, 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 = '131.151.32.21'
dst = '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.sv)
p.add_protocol(v)
p.add_protocol(ip)
p.serialize()
return p