コード例 #1
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 ""
コード例 #2
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 ""
コード例 #3
0
    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
0
    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 ""