def LocalRequest(self): """Local request will trigger the session to send a ICRQ to remote, currently, this function is just for simulator usage. :return: None """ self.logger.debug( "Got a local request to setup the session, will send a ICRQ to remote" ) if isinstance(self.fsm, L2tpv3Fsm.L2tpv3SessionRecipientFsm): self.logger.warn( "Recipient does not support the local request, do nothing.") return if self.fsm.current == L2tpv3Fsm.L2tpv3SessionSenderFsm.StateIdle: msgAvp = L2tpv3RFC3931AVPs.ControlMessageAVP( L2tpv3RFC3931AVPs.ControlMessageAVP.ICRQ) localSessionId = L2tpv3RFC3931AVPs.LocalSessionID( self.localSessionId) remoteSessionId = L2tpv3RFC3931AVPs.RemoteSessionID( self.remoteSessionId) remote_end_id = L2tpv3RFC3931AVPs.RemoteEndID( (((0, 3, 0), 0), ((0, 3, 1), 1))) DepiL2SpecificSublayerSubtype = L2tpv3CableLabsAvps.DepiL2SpecificSublayerSubtype( 3) icrq = L2tpv3ControlPacket.L2tpv3ControlPacket( self.connection.remoteConnID, avps=(msgAvp, localSessionId, remoteSessionId, remote_end_id, DepiL2SpecificSublayerSubtype)) self.connection.transport.SendPacket(icrq) self.fsm.localRequest()
def __init__(self, session, resultCode, errCode, errMsg): connection = session.connection super( L2tpv3CDN, self).__init__(L2tpv3RFC3931AVPs.ControlMessageAVP.CDN, connection.remoteConnID, resultCode, errCode, errMsg) localSessionID = session.localSessionId remoteSessionID = session.remoteSessionId localAvp = L2tpv3RFC3931AVPs.LocalSessionID(localSessionID) remoteAvp = L2tpv3RFC3931AVPs.RemoteSessionID(remoteSessionID) self.avps.append(localAvp) self.avps.append(remoteAvp)
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)
def sendSLI(self): if self.fsm.current == L2tpv3Fsm.L2tpv3SessionRecipientFsm.StateEstablished and\ self.connection and self.connection.transport: msgAvp = L2tpv3RFC3931AVPs.ControlMessageAVP( L2tpv3RFC3931AVPs.ControlMessageAVP.SLI) localSessionId = L2tpv3RFC3931AVPs.LocalSessionID( self.localSessionId) remoteSessionId = L2tpv3RFC3931AVPs.RemoteSessionID( self.remoteSessionId) circuitstatus = L2tpv3RFC3931AVPs.CircuitStatus( active=self.local_circuit_status, new=False) sli = L2tpv3ControlPacket.L2tpv3ControlPacket( self.connection.remoteConnID, avps=(msgAvp, localSessionId, remoteSessionId, circuitstatus)) self.connection.transport.SendPacket(sli) self.logger.info("send SLI status change to remote: " + "local:" + str(self.localSessionId) + " remote:" + str(self.remoteSessionId) + " status:" + str(self.local_circuit_status))
def setUpClass(cls): setupDB() time.sleep(2) HalGlobal.gClientMgr = None HalGlobal.gPoller = None t = threading.Thread(target=demoHalmain) t.daemon = True t.start() time.sleep(2) threads_list.append(t) if not HalGlobal.gClientMgr or not HalGlobal.gPoller: raise Exception("Cannot start the demo halMain") t = threading.Thread(target=demoL2tp) t.daemon = True t.start() time.sleep(2) threads_list.append(t) t = threading.Thread(target=demoDrvmain) t.daemon = True t.start() threads_list.append(t) time.sleep(2) setup_logging('HAL', filename="hal.log", logging_level=logging.DEBUG) cls.logger = logging.getLogger("L2tpHalDrvVspAvpTest") cls.logger.info("hello L2tpHalDrvVspAvpTest Log") cls.stop = False cls.conn_address = '127.0.0.1' # Setup connection/session: set it here since global variables are already only after threads are up. cls.dispatcher = L2tpv3GlobalSettings.Dispatcher cls.hal_client = L2tpv3GlobalSettings.l2tp_hal_client # cls.conn = L2tpConnection.L2tpConnection( # 6661, 6662, cls.conn_address, cls.conn_address) #cls.session = L2tpv3Session.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) cls.avps_icrq = [] cls.avps_icrq.append(localSessionId) cls.avps_icrq.append(remoteSessionId) cls.avps_icrq.append(remoteEnd) cls.avps_icrq.append(remoteEnd_1) cls.avps_icrq.append(DepiL2SpecificSublayerSubtype) cls.avps_icrq.append(LocalMTUCableLabs) cls.avps_icrq.append(pw_type) cls.icrq_buf = struct.pack( '!206B', 0xc8, 0x03, 0x0, 206, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x4, 0xc, 8, 0x0, 0x0, 0x0, 0x0, 0x0, 10, 0xc, 10, 0x0, 0x0, 0, 15, 0, 0, 0, 0, 0xc, 10, 0x0, 0x0, 0, 63, 0x40, 0x01, 0x00, 0x01, 0xc, 10, 0x0, 0x0, 0, 64, 0x0, 0x0, 0x0, 0x0, 0xc, 40, 0x0, 0x0, 0x0, 66, 0x0, 0x0, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x03, 0x02, 0x02, 0x00, 0x03, 0x03, 0x03, 0x00, 0x03, 0x04, 0x04, 0x00, 0x03, 0x05, 0x05, 0x00, 0x03, 0x06, 0x06, 0x00, 0x03, 0x07, 0x07, 0xc, 8, 0, 0, 0, 68, 0, 12, 0xc, 8, 0, 0, 0, 69, 0, 3, 0xc, 8, 0, 0, 0, 71, 0, 2, 0xc, 8, 0x11, 0x8b, 0x0, 0x2, 0x1, 0x0, 0xc, 8, 0x11, 0x8b, 0x0, 0x4, 0x7, 0xD0, 0xc, 20, 0x11, 0x8b, 0x0, 15, 0x0, 0x1, 0x0, 0x2, 0x0, 0x3, 0x0, 0x6, 0x0, 0x8, 0x0, 11, 0x0, 13, 0xc, 8, 0x11, 0x8b, 0x0, 16, 0x0, 0x3, 0xc, 8, 0x11, 0x8b, 0x0, 17, 0x0, 0x3, 0xc, 40, 0x11, 0x8b, 0x0, 11, 0, 0, 0x5, 0x6, 0x7, 0x8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 229, 1, 1, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, )
avp.sessionID = sessionID # Change the AVPs print iccn buf = iccn.encode(True) s.sendto(buf, ('127.0.0.1', 1)) cdnMsg = L2tpv3RFC3931AVPs.ControlMessageAVP( L2tpv3RFC3931AVPs.ControlMessageAVP.CDN) retcode = L2tpv3RFC3931AVPs.ResultCode( L2tpv3RFC3931AVPs.ControlMessageAVP.StopCCN, 0, 0, "test") # Get the lcoal session ID localAvp = None for avp in iccn.avps: if isinstance(avp, L2tpv3RFC3931AVPs.LocalSessionID): lcoalSessionID = avp.sessionID localAvp = L2tpv3RFC3931AVPs.LocalSessionID(lcoalSessionID) remoteAvp = L2tpv3RFC3931AVPs.RemoteSessionID(sessionID) cdn = L2tpv3ControlPacket.L2tpv3ControlPacket(conntionID, avps=(cdnMsg, retcode, localAvp, remoteAvp)) cdn.ns = 4 cdn.nr = 2 cdn.connectionID = conntionID print cdn buf = cdn.encode(True) s.sendto(buf, ('127.0.0.1', 1)) stopccn.ns = 5 stopccn.nr = 2 stopccn.connectionID = conntionID