Exemple #1
0
    def test_PseudowireCapListCisco(self):
        avp1 = PseudowireCapListCisco((1, 2, 3, 4, 5, 6))

        buf = avp1.encode()

        avp2 = l2tpv3AVP.decodeAll(buf)
        print avp2[0]
        print avp1

        ret = avp1.handleAvp(pkt=None, retPak=None)
        self.assertTrue(ret)
        pkt = fake_pkt()
        ret = avp1.handleAvp(pkt=pkt, retPak=pkt)
        self.assertTrue(ret)
        self.assertIsInstance(pkt.avps[0], PseudowireCapListCisco)

        # Add: Start
        # not isinstance(value, tuple) or not isinstance(mustAvp, bool)
        # or not isinstance(hiddenAvp, bool)
        try:
            avp3 = PseudowireCapListCisco(value=2,
                                          mustAvp=2,
                                          hiddenAvp=2,
                                          attrValue=None)
        except Exception as e:
            pass

        # retPak is None
        self.assertEqual(avp1.handleAvp(pkt="0x1234567", retPak=None), True)
        # retPak is Not None
        try:
            avp1.handleAvp(pkt="0x1234567", retPak="NotNone")
        except Exception as e:
            pass
Exemple #2
0
    def test_RemoteSessionIDCisco(self):
        avp1 = RemoteSessionIDCisco(0x12345678)

        buf = avp1.encode()

        avp2 = l2tpv3AVP.decodeAll(buf)
        print avp2[0]
        print avp1
        ret = avp1.handleAvp(pkt=None, retPak=None)
        self.assertTrue(ret)
        pkt = fake_pkt()
        pkt_avp = LocalSessionIDCisco(0x112)
        pkt.avps.append(pkt_avp)
        ret = avp1.handleAvp(pkt=pkt, retPak=pkt)
        self.assertTrue(ret)

        # Add: Start
        # (not isinstance(value, int) and not isinstance(value, long))
        # or not isinstance(hiddenAvp, bool) or not isinstance(mustAvp, bool)
        try:
            avp3 = RemoteSessionIDCisco(value="",
                                        mustAvp=3,
                                        hiddenAvp=1,
                                        attrValue=None)
        except Exception as e:
            pass

        # Test handleAvp
        # retPak is None
        self.assertEqual(avp1.handleAvp(pkt="0x", retPak=None), True)
        # retPak is Not None
        try:
            avp1.handleAvp(pkt="0xcvb", retPak="0x12345")
        except Exception as e:
            pass
Exemple #3
0
    def test_PseudowireTypeCisco(self):
        avp1 = PseudowireTypeCisco(12)

        buf = avp1.encode()

        avp2 = l2tpv3AVP.decodeAll(buf)
        print avp2[0]
        print avp1

        # Add: Start
        # (not isinstance(value, int) and not isinstance(value, long))
        # or not isinstance(hiddenAvp, bool) or not isinstance(mustAvp, bool)
        try:
            avp3 = PseudowireTypeCisco(value="",
                                       mustAvp=3,
                                       hiddenAvp=1,
                                       attrValue=None)
        except Exception as e:
            pass

        # Test handleAvp
        # retPak is None
        self.assertEqual(avp1.handleAvp(pkt="0x", retPak=None), True)
        # retPak is Not None
        try:
            avp1.handleAvp(pkt="0xcvb", retPak="0x12345")
        except Exception as e:
            pass
Exemple #4
0
    def test_DraftAVPVersionCisco(self):
        avp1 = DraftAVPVersionCisco(12)

        buf = avp1.encode()

        avp2 = l2tpv3AVP.decodeAll(buf)
        print avp2[0]
        print avp1

        ret = avp1.handleAvp(pkt=None, retPak=None)
        self.assertTrue(ret)
        pkt = fake_pkt()
        ret = avp1.handleAvp(pkt=pkt, retPak=pkt)
        self.assertTrue(ret)
        self.assertIsInstance(pkt.avps[0], DraftAVPVersionCisco)

        # Add: Start
        # (not isinstance(value, int) and not isinstance(value, long))
        # or not isinstance(hiddenAvp, bool) or not isinstance(mustAvp, bool)
        try:
            avp3 = DraftAVPVersionCisco(value="", attrValue=None)
        except Exception as e:
            self.assertIsInstance(e, l2tpv3AVPerror)

        # attrValue is NOT None
        avp4 = DraftAVPVersionCisco(12, "zyj")

        # Test handleAvp
        # retPak is None
        self.assertEqual(avp1.handleAvp(pkt="0x", retPak=None), True)
        # retPak is Not None
        try:
            avp1.handleAvp(pkt="0xcvb", retPak="0x12345")
        except Exception as e:
            pass
Exemple #5
0
    def decode(buf):
        """Decode a str to control packet. Also the function will invoke the
        AVp's decode function.After this function, all the AVP will be also
        decoded.

        :param buf: Original packet received from from wire.
        :return: a decoded control packet.

        """
        if len(buf) < 12:
            raise L2tpv3PacketError(L2tpv3PacketError.BufferIsTooLow)
        # Get the header fields

        _, length, conn, ns, nr = struct.unpack("!HHIHH", buf[:12])
        if length > len(buf):
            raise L2tpv3PacketError(L2tpv3PacketError.BufferIsTooLow)

        # decode the avps
        avps = l2tpv3AVP.decodeAll(buf[12:length])

        # Genreate the packets
        pkt = L2tpv3ControlPacket(conn, ns, nr, avps, buf[12:length])

        if len(avps) == 0:
            pkt.isZlb = True

        if len(avps) > 0 and \
                isinstance(avps[0], L2tpv3RFC3931AVPs.ControlMessageAVP) and\
                avps[0].messageType == L2tpv3RFC3931AVPs.ControlMessageAVP.ACK:
            pkt.isZlb = True

        return pkt
Exemple #6
0
    def test_AssignedConnectionIDCisco(self):
        avp1 = AssignedConnectionIDCisco(0x12345678)

        buf = avp1.encode()

        avp2 = l2tpv3AVP.decodeAll(buf)
        print avp2[0]
        print avp1
        ret = avp1.handleAvp(pkt=None, retPak=None)
        self.assertTrue(ret)
        pkt = fake_pkt()
        ret = avp1.handleAvp(pkt=pkt, retPak=pkt)
        self.assertTrue(ret)
        self.assertIsInstance(pkt.avps[0], AssignedConnectionIDCisco)

        # Add: Start
        # (not isinstance(value, int) and not isinstance(value, long))\
        # or not isinstance(mustAvp, bool) or not isinstance(hiddenAvp, bool)
        try:
            avp3 = AssignedConnectionIDCisco(value="1011",
                                             mustAvp=12,
                                             hiddenAvp=21,
                                             attrValue=None)
        except Exception as e:
            pass

        # test handleAvp
        # retPak is None and return True
        self.assertEqual(avp1.handleAvp(pkt="0x1234567", retPak=None), True)
        # retPak is Not None

        try:
            avp1.handleAvp(pkt="0x1234567", retPak="0x232332ss")
        except Exception as e:
            pass
Exemple #7
0
 def test_Upstreamflow(self):
     avp1 = UpstreamFlow(((1, 2), (4, 5)))
     print avp1
     buf = avp1.encode()
     print len(buf)
     avp2 = l2tpv3AVP.decodeAll(buf)
     print avp2[0]
     print avp1
Exemple #8
0
 def test_ResourceAlloc(self):
     avp1 = DepiResourceAllocReplyCableLabs(((1, 2), (4, 5)))
     print avp1
     buf = avp1.encode()
     print len(buf)
     avp2 = l2tpv3AVP.decodeAll(buf)
     print avp2[0]
     print avp1
Exemple #9
0
    def test_DepiRemoteMulticastJoin(self):
        data = DepiRemoteMulticastJoin.decode(struct.pack("!34B", 0x00, 0x00,
                                                          0x1, 0x1, 0x2, 0x1,
                                                          0x00, 0x00, 0x00, 0x00,
                                                          0x00, 0x00, 0x00, 0x00,
                                                          0x00, 0x00, 0x00, 0x00,
                                                          0x1, 0x1, 0x1, 0x1,
                                                          0x00, 0x00, 0x00, 0x00,
                                                          0x00, 0x00, 0x00, 0x00,
                                                          0x00, 0x00, 0x00, 0x00
                                                          ))
        self.assertIsInstance(data, DepiRemoteMulticastJoin)
        self.assertEqual(data.src_ip, "1.1.2.1")
        self.assertEqual(data.group_ip, "1.1.1.1")

        data = DepiRemoteMulticastJoin.decode(struct.pack("!34B", 0x00, 0x00,
                                                          0x11, 0x11, 0x11, 0x11,
                                                          0x11, 0x11, 0x11, 0x11,
                                                          0x11, 0x11, 0x11, 0x11,
                                                          0x11, 0x11, 0x11, 0x11,
                                                          0x11, 0x11, 0x11, 0x11,
                                                          0x11, 0x11, 0x11, 0x11,
                                                          0x11, 0x11, 0x11, 0x12,
                                                          0x11, 0x11, 0x11, 0x11
                                                          ))

        self.assertIsInstance(data, DepiRemoteMulticastJoin)
        self.assertEqual("1111:1111:1111:1111:1111:1111:1111:1111", data.src_ip)
        self.assertEqual("1111:1111:1111:1111:1111:1112:1111:1111", data.group_ip)

        avp1 = DepiRemoteMulticastJoin(value=("5.5.5.1", "223.222.222.255"))
        buf = avp1.encode()
        avp2 = l2tpv3AVP.decodeAll(buf)
        print avp2[0]
        print avp1
        self.assertEqual(avp1.src_ip, avp2[0].src_ip)
        self.assertEqual(avp1.group_ip, avp2[0].group_ip)
        avp1 = DepiRemoteMulticastJoin(value=("2001:5:5:3::0:1", "2001:5:5::0:1"))
        buf = avp1.encode()
        avp2 = l2tpv3AVP.decodeAll(buf)
        print avp2[0]
        print avp1
        self.assertEqual(avp1.src_ip, avp2[0].src_ip)
        self.assertEqual(avp1.group_ip, avp2[0].group_ip)
Exemple #10
0
    def test_RemoteMTU(self):
        avp1 = RemoteMTUCableLabs(1234)

        buf = avp1.encode()

        avp2 = l2tpv3AVP.decodeAll(buf)
        print avp2[0]
        print avp1
        ret = avp1.handleAvp(pkt=None, retPak=None)
        self.assertTrue(ret)
Exemple #11
0
 def test_DepiPseudowireSubtypeCapList(self):
     avp1 = DepiPseudowireSubtypeCapList(value=(1, 2, 3, 4))
     buf = avp1.encode()
     avp2 = l2tpv3AVP.decodeAll(buf)
     print avp2
     print avp1
     ret = avp1.handleAvp(pkt=None, retPak=None)
     self.assertTrue(ret)
     pkt = L2tpv3ControlPacket.L2tpv3ControlPacket()
     ret = avp1.handleAvp(pkt=None, retPak=pkt)
     self.assertTrue(ret)
     self.assertIsInstance(pkt.avps[0], DepiPseudowireSubtypeCapList)
     self.assertEqual(pkt.avps[0].pw_list, (1, 2, 3, 4))
Exemple #12
0
 def test_DepiL2SpecificSublayerSubtype(self):
     avp1 = DepiL2SpecificSublayerSubtype(value=3)
     buf = avp1.encode()
     avp2 = l2tpv3AVP.decodeAll(buf)
     print avp2
     print avp1
     ret = avp1.handleAvp(pkt=None, retPak=None)
     self.assertTrue(ret)
     pkt = L2tpv3ControlPacket.L2tpv3ControlPacket()
     ret = avp1.handleAvp(pkt=None, retPak=pkt)
     self.assertTrue(ret)
     self.assertIsInstance(pkt.avps[0], DepiL2SpecificSublayerSubtype)
     self.assertEqual(pkt.avps[0].pw_type, avp1.pw_type)
Exemple #13
0
 def test_DepiMulticastCapability(self):
     avp1 = DepiMulticastCapability(value=True)
     buf = avp1.encode()
     avp2 = l2tpv3AVP.decodeAll(buf)
     print avp2
     print avp1
     ret = avp1.handleAvp(pkt=None, retPak=None)
     self.assertTrue(ret)
     pkt = L2tpv3ControlPacket.L2tpv3ControlPacket()
     ret = avp1.handleAvp(pkt=None, retPak=pkt)
     self.assertTrue(ret)
     mcast_cap = self.hal_client.mcast_cap
     self.assertIsInstance(pkt.avps[0], DepiMulticastCapability)
     self.assertEqual(pkt.avps[0].mcast_capable, mcast_cap)
Exemple #14
0
 def test_LocalMTU(self):
     avp1 = LocalMTUCableLabs(1234)
     buf = avp1.encode()
     avp2 = l2tpv3AVP.decodeAll(buf)
     self.assertEqual(avp2[0].localMTU, 1234)
     self.assertEqual(avp1.localMTU, 1234)
     # test handleAvp
     ret = avp1.handleAvp(pkt=None, retPak=None)
     self.assertTrue(ret)
     pkt = L2tpv3ControlPacket.L2tpv3ControlPacket()
     ret = avp1.handleAvp(pkt=None, retPak=pkt)
     mtu_payload = self.hal_client.mtu_payload
     self.assertTrue(ret)
     self.assertIsInstance(pkt.avps[0], RemoteMTUCableLabs)
     self.assertEqual(pkt.avps[0].localMTU, mtu_payload)
Exemple #15
0
 def test_ResourceAllocReq(self):
     avp1 = DepiResourceAllocReq(value=((0, 1), (2, 3)))
     print avp1
     buf = avp1.encode()
     print len(buf)
     avp2 = l2tpv3AVP.decodeAll(buf)
     print avp2[0]
     print avp1
     # test handleAvp
     ret = avp1.handleAvp(pkt=None, retPak=None)
     self.assertTrue(ret)
     pkt = L2tpv3ControlPacket.L2tpv3ControlPacket()
     ret = avp1.handleAvp(pkt=None, retPak=pkt)
     self.assertTrue(ret)
     self.assertIsInstance(pkt.avps[0], DepiResourceAllocReplyCableLabs)
     self.assertEqual(pkt.avps[0].allocas, ((0, 1), (2, 3)))
Exemple #16
0
    def test_LocalSessionIDCisco(self):
        avp1 = LocalSessionIDCisco(0x12345678)

        buf = avp1.encode()

        avp2 = l2tpv3AVP.decodeAll(buf)
        print avp2[0]
        print avp1

        ret = avp1.handleAvp(pkt=None, retPak=None)
        self.assertTrue(ret)
        pkt = fake_pkt()
        ret = avp1.handleAvp(pkt=pkt, retPak=pkt)
        self.assertFalse(ret)
        pkt.Session = fake_sess()
        ret = avp1.handleAvp(pkt=pkt, retPak=pkt)
        self.assertTrue(ret)
        self.assertIsInstance(pkt.avps[0], LocalSessionIDCisco)

        # Add: Start
        # (not isinstance(value, int) and not isinstance(value, long)) \
        # or not isinstance(hiddenAvp, bool) or not isinstance(mustAvp, bool)
        try:
            avp3 = LocalSessionIDCisco(value="null",
                                       mustAvp=0,
                                       hiddenAvp=0,
                                       attrValue=None)
        except Exception as e:
            pass

        # Test handleAvp
        # retPak is None
        self.assertEqual(avp1.handleAvp(pkt="0x", retPak=None), True)
        # retPak is Not None
        try:
            avp1.handleAvp(pkt="0xcvb", retPak="0x12345")
        except Exception as e:
            pass
Exemple #17
0
    def test_DepiMcmtsSimplificationCisco(self):
        avp1 = DepiMcmtsSimplificationCisco(1, 2, "hello")

        buf = avp1.encode()

        avp2 = l2tpv3AVP.decodeAll(buf)
        print avp2[0]
        print avp1

        ret = avp1.handleAvp(pkt=None, retPak=None)
        self.assertTrue(ret)
        pkt = fake_pkt()
        ret = avp1.handleAvp(pkt=pkt, retPak=pkt)
        self.assertTrue(ret)
        self.assertIsInstance(pkt.avps[0], DepiMcmtsSimplificationCisco)
        # Add: Start
        # isinstance(value, str) or (not isinstance(typeDef, int) and not isinstance(typeDef, long))
        # or (not isinstance(version, int) and not isinstance(version, long))
        try:
            avp3 = DepiMcmtsSimplificationCisco(typeDef="234",
                                                version="wwq",
                                                value=0,
                                                attrValue=None)
        except Exception as e:
            self.assertEqual(str(e), "parameter type error")

        # attrValue is NOT None
        avp4 = DepiMcmtsSimplificationCisco(12, 11, "zyj")

        # Test handleAvp
        # retPak is None
        self.assertEqual(avp1.handleAvp(pkt="0x", retPak=None), True)
        # retPak is Not None
        try:
            avp1.handleAvp(pkt="0xcvb", retPak="0x12345")
        except Exception as e:
            pass
Exemple #18
0
 def test_DepiPseudowireSubtype(self):
     avp1 = DepiPseudowireSubtype(value=3)
     buf = avp1.encode()
     avp2 = l2tpv3AVP.decodeAll(buf)
     print avp2
     print avp1