Beispiel #1
0
 def test_end_ipv4_valid(self):
     packet_in = \
         Ether(src="aa:aa:aa:aa:aa:aa", dst="bb:bb:bb:bb:bb:bb") / \
         IPv6(src="fc00::1", dst="fc00::3") / \
         IPv6ExtHdrSegmentRouting(len=(16 * 2) / 8, segleft=1, lastentry=1, addresses=["fc00::2", "fc00::3"]) / \
         IP(src="192.168.1.1", dst="192.168.1.3") / \
         TCP()
     packet_out = \
         Ether(src="bb:bb:bb:bb:bb:bb", dst="aa:aa:aa:aa:aa:aa") / \
         IPv6(src="fc00::1", dst="fc00::2") / \
         IPv6ExtHdrSegmentRouting(len=(16 * 2) / 8, segleft=0, lastentry=1, addresses=["fc00::2", "fc00::3"]) / \
         IP(src="192.168.1.1", dst="192.168.1.3") / \
         TCP()
     self._run_test(packet_in, packet_out, BPF.XDP_TX)
Beispiel #2
0
    def test_consistency(self):
        conf.iface6 = "A-0"

        ip6 = IPv6(src=self.sfc[-1], dst=self.sfc[0])
        sr = IPv6ExtHdrSegmentRouting(addresses=self.sfc[::-1],
                                      nseg=len(self.sfc) - 1,
                                      fseg=len(self.sfc) - 1)
        hdr = (ip6 / sr)

        matching = lambda a, b: tt.Utils.inner_IPv6(a) == tt.Utils.inner_IPv6(b
                                                                              )

        def craft(hdr, fl):
            tt.Utils.set_fl(hdr, fl)
            pkt = hdr / IPv6() / ICMPv6EchoRequest()

            pkt = pkt.__class__(str(pkt))

            return ([pkt], {fl: [pkt]})

        sns = tt.Tester(
            tt.Test(ct.Crafter(hdr, craft), [sn.filter_ICMP, sn.filter_SEG],
                    mt.Matcher(matching)))

        self.assertTrue(sns.perform_test())
Beispiel #3
0
 def test_end_ipv4_segment_left_zero(self):
     packet_in = \
         Ether(src="aa:aa:aa:aa:aa:aa", dst="bb:bb:bb:bb:bb:bb") / \
         IPv6(src="fc00::1", dst="fc00::3") / \
         IPv6ExtHdrSegmentRouting(len=(16 * 2) / 8, segleft=0, lastentry=0, addresses=["fc00::3"]) / \
         IP(src="192.168.1.1", dst="192.168.1.3") / \
         TCP()
     self._run_test(packet_in, None, BPF.XDP_DROP)
Beispiel #4
0
    def setUp(self):
        self.conf = helpers.get_conf()
        self.sfc = helpers.addr_services(self.conf, BulkListTestCase.services)

        ip6 = IPv6(src=self.sfc[-1], dst=self.sfc[0])
        sr = IPv6ExtHdrSegmentRouting(addresses=self.sfc[::-1],
                                      nseg=len(self.sfc) - 1,
                                      fseg=len(self.sfc) - 1)
        self.hdr = (ip6 / sr / IPv6())

        self.sport = 50000
        self.dport = 60000
Beispiel #5
0
 def test_encap_ipv6_two_segment(self):
     packet_in = \
         Ether(src="aa:aa:aa:aa:aa:aa", dst="bb:bb:bb:bb:bb:bb") / \
         IPv6(src="2001:db8::1", dst="2001:db8::3") / \
         TCP()
     packet_out = \
         Ether(src="bb:bb:bb:bb:bb:bb", dst="aa:aa:aa:aa:aa:aa") / \
         IPv6(src="fc00::1", dst="fc00::3") / \
         IPv6ExtHdrSegmentRouting(len=(16 * 2) / 8, segleft=1, lastentry=1, addresses=["fc00::2", "fc00::3"]) / \
         IPv6(src="2001:db8::1", dst="2001:db8::3") / \
         TCP()
     self._run_test(packet_in, packet_out, BPF.XDP_TX)
Beispiel #6
0
    def test_packet_pass(self):
        conf.iface6 = "A-0"

        ip6 = IPv6(src=self.sfc[-1], dst=self.sfc[0])
        sr = IPv6ExtHdrSegmentRouting(addresses=self.sfc[::-1])
        hdr = (ip6 / sr)

        def craft(hdr, fl):
            helpers.Utils.set_fl(hdr, fl)
            pkt = hdr / IPv6() / ICMPv6EchoRequest()

            pkt = pkt.__class__(str(pkt))

            return ([pkt], {fl: [pkt]})

        sns = tt.Tester(
            tt.Test(ct.Crafter(hdr, craft, 1, 1, 5),
                    [sn.filter_ICMP, sn.filter_SEG], mt.Matcher()))
        self.assertTrue(sns.perform_test())
Beispiel #7
0
def srv6_traceroute(destination, result_table, packet_len, max_ttl, sr_hops,
                    verbosity, timeout):
    ttl = 1

    while ttl <= max_ttl:
        p = sr1(IPv6(dst=destination, hlim=ttl) /
                IPv6ExtHdrSegmentRouting(addresses=sr_hops) /
                ICMPv6EchoRequest(data=RandString(packet_len)),
                timeout=timeout,
                verbose=verbosity)

        if p is not None:
            if not ttl in result_table:
                result_table[ttl] = {}
            result_table[ttl]["SR"] = p[IPv6].src
        else:
            result_table[ttl]["SR"] = "-"

        ttl += 1

    return result_table
Beispiel #8
0
    def test_disordered_refrag(self):
        nbrFlux = 4

        ip6 = IPv6(src=self.sfc[-1], dst=self.sfc[0])
        sr  = IPv6ExtHdrSegmentRouting(addresses=self.sfc[::-1],
                                nseg=len(self.sfc) - 1, fseg=len(self.sfc) - 1)
        hdr = (ip6/sr)

        def matching(a,b):
            return Utils.inner_IPv6(a) == Utils.inner_IPv6(b)

        def craft(hdr, fl):
            snd = []
            rcv = {}

            for fl in range(fl, fl+nbrFlux):
                Utils.set_fl(hdr, fl)

                sip = 'fc00:2:0:1::1' # Adresses don't rlly matter
                dip = 'fc00:2:0:2::1'

                packets_snd = fragment6(IPv6(src=sip, dst=dip) / IPv6ExtHdrFragment() / ICMPv6EchoRequest(data='A'*300), 100)
                packets_snd = [pkt.__class__(str(hdr/pkt)) for pkt in packets_snd]
                packet_excepted = pkt.__class__(str(hdr/IPv6(src=sip, dst=dip) / ICMPv6EchoRequest(data='A'*300)))

                snd.extend(packets_snd)
                random.shuffle(snd) # shuffle
                rcv[fl] = [packet_excepted]

            return (snd, rcv)

        sns = Tester(Test(
            ct.Crafter(hdr, craft, nbr_flux=nbrFlux,
                       nbr_expected=nbrFlux),
            [sn.filter_ICMP, sn.filter_SEG],
            Matcher(matching)
        ))
        self.assertTrue(sns.perform_test())