Example #1
0
    def test_l2tp_arp_learn(self):
        self.hal_client.arp_addr_dict["127.0.0.2"] = "00:00:00:00:00:00"
        self.hal_client.arp_addr_dict["127.0.0.1"] = "00:00:00:00:00:00"
        self.hal_client.startL2tpReCfgTimer()

        self.fwdCfg = StaticL2tpProvision()
        staticPwCfg = StaticPwConfig_pb2.t_StaticPwConfig()
        self.fwdCfg.add_commStaticSession(staticPwCfg, 12, 0x80000001, 4,
                                          32768, True)
        self.fwdCfg.add_usStaticSession(staticPwCfg, 12, False)
        session1 = L2tpv3GcppSession.StaticL2tpSession(12)
        session1.updateRetstaticPseudowire(staticPwCfg)
        session1.updateComStaticPseudowire(staticPwCfg)
        session1.destAddress = "127.0.0.1"
        session1.write()

        staticPwCfg = StaticPwConfig_pb2.t_StaticPwConfig()
        self.fwdCfg.add_commStaticSession(staticPwCfg, 12, 0x80000002, 5,
                                          32768, True)
        self.fwdCfg.add_usStaticSession(staticPwCfg, 12, False)
        session2 = L2tpv3GcppSession.StaticL2tpSession(12)
        session2.updateRetstaticPseudowire(staticPwCfg)
        session2.updateComStaticPseudowire(staticPwCfg)
        session2.destAddress = "127.0.0.2"
        session2.write()
        self.hal_client.update_us_l2tp_session_cfg(1)
        time.sleep(10)

        remoteMac = L2tpHalClient.get_mac_bytes_from_ip(session1.destAddress)
        self.assertNotEquals(remoteMac, "00:00:00:00:00:00")
        remoteMac = L2tpHalClient.get_mac_bytes_from_ip(session2.destAddress)
        self.assertNotEquals(remoteMac, "00:00:00:00:00:00")
        session1.delete()
        session2.delete()
Example #2
0
    def test_lcceID_good_recvCfgMsgRspCb(self):
        self.conn.fsm.recvGoodSCCRQ()
        self.conn.fsm.recvGoodSCCCN()
        rsp = L2tpv3Hal_pb2.t_l2tpLcceAssignmentRsp()
        rsp.lcce_id = self.conn.localConnID
        rsp.lcce_info.local_ip = "10.79.41.138"
        rsp.lcce_info.remote_ip = "10.79.41.139"
        rsp.lcce_info.local_mac = L2tpHalClient.get_mac_of_ip(rsp.lcce_info.local_ip)
        rsp.lcce_info.remote_mac = L2tpHalClient.get_mac_of_ip(rsp.lcce_info.remote_ip)
        rsp.lcce_info.mtu = 2342
        rsp.result = True
        payload = rsp.SerializeToString()
        msg = HalMessage("HalConfigRsp", SrcClientID="123", SeqNum=3,
                         Rsp={
                             "Status": HalCommon_pb2.SUCCESS,
                             "ErrorDescription": ""
                         },
                         CfgMsgType=HalConfigMsg.MsgTypeL2tpv3LcceIdAssignment,
                         CfgMsgPayload=payload)
        ret = self.hal_client.recvCfgMsgRspCb(msg)
        self.assertTrue(ret)

        # case exception
        self.hal_client.handler = None
        try:
            ret = self.hal_client.recvCfgMsgRspCb(msg)
            self.hal_client.handler = L2tpv3GlobalSettings.Dispatcher.receive_hal_message
        except L2tpHalClientError as e:
            pass
Example #3
0
    def test_lcceId_bad_recvCfgMsgRspCb_NOTSUUPPORT(self):
        self.conn.fsm.recvGoodSCCRQ()
        self.conn.fsm.recvGoodSCCCN()
        rsp = L2tpv3Hal_pb2.t_l2tpLcceAssignmentReq()
        rsp.lcce_id = self.conn.localConnID
        rsp.lcce_info.local_ip = "10.79.41.138"
        rsp.lcce_info.remote_ip = "10.79.41.139"
        rsp.lcce_info.local_mac = L2tpHalClient.get_mac_of_ip(rsp.lcce_info.local_ip)
        rsp.lcce_info.remote_mac = L2tpHalClient.get_mac_of_ip(rsp.lcce_info.remote_ip)
        rsp.lcce_info.mtu = 2342
        rsp.msg_type = L2tpv3Hal_pb2.t_l2tpLcceAssignmentReq.ADD_L2TPv3_LCCE
        payload = rsp.SerializeToString()
        msg = HalMessage("HalConfigRsp", SrcClientID="123", SeqNum=3,
                         Rsp={
                             "Status": HalCommon_pb2.NOTSUPPORTED,
                             "ErrorDescription": ""
                         },
                         CfgMsgType=HalConfigMsg.MsgTypeL2tpv3LcceIdAssignment,
                         CfgMsgPayload=payload)
        ret = self.hal_client.recvCfgMsgRspCb(msg)
        self.assertFalse(ret)

        # case exception
        fake_msg = HalMessage("HalClientRegisterRsp",
                              Rsp={
                                  "Status": HalCommon_pb2.NOTSUPPORTED,
                                  "ErrorDescription": ""
                              },
                              ClientID="214")
        ret = self.hal_client.recvCfgMsgRspCb(cfg=fake_msg)
        self.assertFalse(ret)
Example #4
0
    def test_get_local_mac(self):
        ipaddr = "127.0.0.1"
        ret = L2tpHalClient.get_local_mac(ipaddr)
        self.assertIsNotNone(ret)

        ipaddr = "::1"
        ret = L2tpHalClient.get_local_mac(ipaddr)
        self.assertIsNotNone(ret)
        """
Example #5
0
 def test_get_gateway(self):
     ipaddr = "127.0.0.1"
     ret = L2tpHalClient.get_gateway(ipaddr)
     self.assertEqual(ret, "127.0.0.1")
     ipaddr = "10.79.41.136"
     ret = L2tpHalClient.get_gateway(ipaddr)
     print ret
     ipaddr = "10.1.1.1"
     ret = L2tpHalClient.get_gateway(ipaddr)
     print ret
Example #6
0
def demoL2tp():
    print "demoL2tp thread start!"
    setup_logging('HAL', filename="hal.log", logging_level=logging.DEBUG)
    drv_logger = logging.getLogger("demoL2tp")
    drv_logger.info("hello demoL2tp Log")

    dispatcher = Dispatcher()
    l2tp_dispatcher = L2tpv3Dispatcher(
        dispatcher,
        local_addr=None,
        # since we don't create global listen, set it to None
        create_global_listen=False)
    L2tpv3GlobalSettings.Dispatcher = l2tp_dispatcher

    # setup the halclient
    SupportedCfgMsg = list()
    SupportedCfgMsg.append(MsgTypeVspAvpExchange)
    notificationMsg = list()
    notificationMsg.append(MsgTypeL2tpv3SessionStatusNotification)
    hal_client = L2tpHalClient("L2TP_HAL_CLIENT",
                               "the HAL client of L2TP feature", "1.0",
                               tuple(notificationMsg), dispatcher,
                               SupportedCfgMsg)
    L2tpv3GlobalSettings.l2tp_hal_client = hal_client
    hal_client.start(l2tp_dispatcher.receive_hal_message)
    if L2tpv3GlobalSettings.l2tp_hal_client:
        print("setup l2tp hal client successfully")

    if L2tpv3GlobalSettings.Dispatcher:
        print("l2tp_dispatcher is OK")
        print l2tp_dispatcher

    l2tp_dispatcher.dispatcher.loop()
    print "demoL2tp thread done!"
Example #7
0
    def test_handleStatsQuery(self):
        cmd = l2tpMsg.L2tpCommandReq()
        cmd.cmd = l2tpMsg.STATS_INFO
        msg = self.api._handleMsg(cmd)
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.Dispatcher = None
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.l2tp_hal_client = None
        print msg

        global_dispatcher = Dispatcher()
        dispatcher = L2tpv3Dispatcher.L2tpv3Dispatcher(global_dispatcher,
                                                       "127.0.0.1", False,
                                                       None)
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.Dispatcher = dispatcher
        dispatcher.stats.exception = 1
        dispatcher.stats.zmq_error = 1
        dispatcher.stats.error = 1
        # setup the halclient
        hal_client = L2tpHalClient("L2TP_HAL_CLIENT",
                                   "the HAL client of L2TP feature", "1.0",
                                   (3078, ), global_dispatcher)
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.l2tp_hal_client = hal_client
        hal_client.stats.exception = 10
        msg = self.api._handleMsg(cmd)
        print msg
        hal_client.stats = None
Example #8
0
 def test_get_mac_of_ip(self):
     ipaddr = "127.0.0.1"
     ret = L2tpHalClient.get_mac_of_ip(ipaddr)
     self.assertEqual(ret, "00:00:00:00:00:00")
     ipaddr = "10.79.41.137"
     ret = L2tpHalClient.get_mac_of_ip(ipaddr)
     print ret
     ipaddr = "10.1.1.1"
     ret = L2tpHalClient.get_mac_of_ip(ipaddr)
     print ret
     ipaddr = "::1"
     ret = L2tpHalClient.get_mac_of_ip(ipaddr)
     self.assertEqual(ret, "00:00:00:00:00:00")
     ipaddr = "202:201:304:506::1"
     ret = L2tpHalClient.get_mac_of_ip(ipaddr)
     print ret
Example #9
0
    def __init__(self, simulate_mode=False, agent_id=agent.ProcessAgent.AGENTTYPE_L2TP):

        super(L2tpAgent, self).__init__(agent_id)
        # The follow code is used to initialize l2tp
        # get the l2tp configuration path

        dispatcher = self.dispatcher
        l2tp_dispatcher = L2tpv3Dispatcher.L2tpv3Dispatcher(
            dispatcher,
            local_addr=None,
            # since we don't create global listen, set it to None
            create_global_listen=False)
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.Dispatcher = l2tp_dispatcher

        # setup the halclient
        hal_client = L2tpHalClient("L2TP_HAL_CLIENT",
                                   "the HAL client of L2TP feature",
                                   "1.0", tuple(L2tpHalClient.notification_list.keys()), dispatcher,
                                   L2tpHalClient.supportmsg_list)
        L2tpv3GlobalSettings.L2tpv3GlobalSettings.l2tp_hal_client = hal_client
        hal_client.start(l2tp_dispatcher.receive_hal_message)

        if L2tpv3GlobalSettings.L2tpv3GlobalSettings.l2tp_hal_client:
            self.logger.info("setup l2tp hal client successfully")

        # Construct the API transport path
        ApiPath = L2tpv3GlobalSettings.L2tpv3GlobalSettings.APITransportPath
        api = L2tpv3API.L2tpv3API(ApiPath)
        l2tp_dispatcher.register_zmq(api)

        self.l2tp_dispatcher = l2tp_dispatcher

        # the l2tp connection which will be checked, the schema is as follows:
        # (local_addr, remote_addr): {
        #   "status" : UP/DOWN
        #   "lastChangeTime": time()
        #   "id":core id
        # }
        self.l2tp_status = dict()

        self.register_poll_timer(1, self._check_l2tp_status_callback, None)
        self.counter = 0

        # setup link sock to get the link state change
        self.linksock = socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, socket.NETLINK_ROUTE)
        self.linksock.bind((os.getpid(), self.RTMGRP_LINK))
        self.dispatcher.fd_register(self.linksock.fileno(),
                                    zmq.POLLIN, self.process_link_status)

        self.pingSocket = None
        self.dispatcher.timer_register(self.ARP_LEARN_TIME,
                                       self.learn_arp_us_l2tp_session,
                                       None,
                                       timer_type=DpTimerManager.TIMER_REPEATED)
Example #10
0
 def setUpClass(cls):
     cls.conn_address = '127.0.0.1'
     setup_test_redis()
     global_dispatcher = Dispatcher()
     dispatcher = L2tpv3Dispatcher(global_dispatcher, cls.conn_address, False, None)
     L2tpv3GlobalSettings.Dispatcher = dispatcher
     # setup the halclient
     cls.hal_client = L2tpHalClient("L2TP_HAL_CLIENT",
                                    "the HAL client of L2TP feature",
                                    "1.0", tuple(L2tpHalClient.notification_list.keys()), global_dispatcher)
     cls.hal_client.handler = dispatcher.receive_hal_message
     L2tpv3GlobalSettings.l2tp_hal_client = cls.hal_client
     pass
Example #11
0
    def setUpClass(cls):
        # open logger
        setup_logging("L2TP")
        setup_test_redis()

        cls.conn_address = '127.0.0.1'
        global_dispatcher = Dispatcher()
        dispatcher = L2tpv3Dispatcher(
            global_dispatcher, cls.conn_address, False, None)
        L2tpv3GlobalSettings.Dispatcher = dispatcher
        # setup the halclient

        notification_list = list()
        notification_list.append(
            HalConfigMsg.MsgTypeL2tpv3SessionStatusNotification)

        cls.hal_client = L2tpHalClient("L2TP_HAL_CLIENT",
                                       "the HAL client of L2TP feature",
                                       "1.0", tuple(L2tpHalClient.notification_list.keys()), global_dispatcher)

        cls.hal_client.handler = dispatcher.receive_hal_message
        cls.conn = L2tpConnection(
            6661, 6662, cls.conn_address, cls.conn_address)
        cls.session = L2tpv3Session(6661, 6662, 'receiver', cls.conn)
        cls.conn.addSession(cls.session)
        localSessionId = L2tpv3RFC3931AVPs.LocalSessionID(6661)
        remoteSessionId = L2tpv3RFC3931AVPs.RemoteSessionID(6662)
        remoteEnd = L2tpv3RFC3931AVPs.RemoteEndID(
            (((0, 3, 0), 0), ((0, 3, 1), 1), ((0, 3, 2), 2)))
        remoteEnd_1 = L2tpv3RFC3931AVPs.RemoteEndID(
            (((0, 3, 3), 3), ((0, 3, 4), 4), ((0, 3, 5), 5)))
        pw_type = L2tpv3RFC3931AVPs.L2SpecificSublayer(3)
        DepiL2SpecificSublayerSubtype = L2tpv3CableLabsAvps.DepiL2SpecificSublayerSubtype(3)
        LocalMTUCableLabs = L2tpv3CableLabsAvps.LocalMTUCableLabs(1500)
        DepiRemoteMulticastJoin = L2tpv3CableLabsAvps.DepiRemoteMulticastJoin(("5.5.5.1", "229.1.1.255"))
        DepiResourceAllocReq = L2tpv3CableLabsAvps.DepiResourceAllocReq(((0, 1), (1, 2)))
        UpstreamFlow = L2tpv3CableLabsAvps.UpstreamFlow(((0, 1), (1, 2)))

        cls.session.avps_icrq.append(localSessionId)
        cls.session.avps_icrq.append(remoteSessionId)
        cls.session.avps_icrq.append(remoteEnd)
        cls.session.avps_icrq.append(remoteEnd_1)
        cls.session.avps_icrq.append(DepiL2SpecificSublayerSubtype)
        cls.session.avps_icrq.append(LocalMTUCableLabs)
        cls.session.avps_icrq.append(pw_type)
        cls.session.avps_icrq.append(DepiRemoteMulticastJoin)
        cls.session.avps_icrq.append(DepiResourceAllocReq)
        cls.session.avps_icrq.append(UpstreamFlow)
Example #12
0
 def setUpClass(cls):
     setup_logging("GCPP Unit test")
     setup_test_redis()
     cls.fwdCfg = StaticL2tpProvision()
     cls.ApiPath = \
         L2tpv3GlobalSettings.L2tpv3GlobalSettings.APITransportPath
     cls.api = L2tpv3API(cls.ApiPath)
     global_dispatcher = Dispatcher()
     cls.hal_client = L2tpHalClient("L2TP_HAL_CLIENT",
                                    "the HAL client of L2TP feature", "1.0",
                                    tuple(
                                        L2tpHalClient.notification_list.keys()),
                                    global_dispatcher)
     cls.hal_client.pushSock = HalTransport(
         HalTransport.HalTransportClientAgentPull,
         HalTransport.HalClientMode, index=19,
         socketMode=HalTransport.HalSocketPushMode,
         disconnectHandlerCb=None)
Example #13
0
 def test_get_mac_bytes_from_ip(self):
     ipaddr = "10.1.1.1"
     ret = L2tpHalClient.get_mac_bytes_from_ip(ipaddr)
     mac = struct.unpack("!6B", ret)
     print mac
Example #14
0
 def test_get_route_table(self):
     route_table = L2tpHalClient.get_route_table()
     print route_table
     self.assertIsNotNone(route_table)