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 ""
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
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 ""
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)
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)