Пример #1
0
    def recvSCCRQ(self, pkt):
        """Receive SCCRQ."""
        if L2tpv3GlobalSettings.L2tpv3GlobalSettings.MustAvpsCheck is True:
            ret = self.checkMustAvps(
                L2tpv3ControlPacket.L2tpv3ControlPacket.SCCRQMandatoryAVPs,
                pkt.avps)
            if ret is not True:
                self.fsm.recvBadSCCRQ()
                return L2tpv3ControlPacket.L2tpv3StopCCN(
                    self, 2, 4, "Avp cannot handled correctly")
        sccrpAvp = L2tpv3RFC3931AVPs.ControlMessageAVP(
            L2tpv3RFC3931AVPs.ControlMessageAVP.SCCRP)
        recvWinSize = ReceiveWinSize(
            L2tpv3GlobalSettings.L2tpv3GlobalSettings.ReceiveWindowSize)

        sccrp = L2tpv3ControlPacket.L2tpv3ControlPacket(
            self.remoteConnID, 0, 0, (sccrpAvp, recvWinSize))

        if len(pkt.avps) > 1:
            for i in xrange(1, len(pkt.avps)):
                avp = pkt.avps[i]
                # We got a bad SCCRQ, we should send a CDN
                if not avp.handleAvp(pkt, sccrp):
                    self.fsm.recvBadSCCRQ()
                    return L2tpv3ControlPacket.L2tpv3StopCCN(
                        self, 2, 4, "Avp cannot handled correctly")
        self.fsm.recvGoodSCCRQ()
        return sccrp
Пример #2
0
    def CloseConnection(self):
        """Clean up the resource, including the following parts:

        * sessions
        * transport
        * fsm

        :return: none

        """
        if self.connection_status == L2tpConnection.CREATED:
            keys = self.sessions.keys()
            for sessionId in keys:
                session = self.sessions[sessionId]
                if hasattr(session.fsm.fsm, 'transition'):
                    delattr(session.fsm.fsm, 'transition')
                    self.logger.debug("The session %d fsm is undergoing!!",
                                      sessionId)
                session.CloseSession()
                self.removeSession(session)
            # Send a StopCCN
            self.transport.SendPacket(
                L2tpv3ControlPacket.L2tpv3StopCCN(self, 1, 0,
                                                  "Close the connection"),
                None)

            # process the transport
            self.transport.CloseTransport()

            # remove it from the global connection DB
            self.ConnectionDb.pop(
                (self.remoteAddr, self.localAddr, self.localConnID))
            self.connection_status = L2tpConnection.CLOSED
Пример #3
0
    def recvSCCRP(self, pkt):
        """On openRPD, we will behave as an recipient, so we will not receive
        SCCRP in normal case.

        :param pkt:
        :return:

        """
        self.logger.debug("Receive a SCCRP packet")

        if L2tpv3GlobalSettings.L2tpv3GlobalSettings.MustAvpsCheck is True:
            ret = self.checkMustAvps(
                L2tpv3ControlPacket.L2tpv3ControlPacket.SCCRPMandatoryAVPs,
                pkt.avps)
            if ret is not True:
                self.fsm.recvBadSCCRP()
                return L2tpv3ControlPacket.L2tpv3StopCCN(
                    self, 2, 4, "Avp cannot handled correctly")
        # Get the localAssignedID from the SCCRP
        remoteConnID = 0
        for avp in pkt.avps:
            if isinstance(avp, L2tpv3RFC3931AVPs.AssignedControlConnectionID):
                remoteConnID = avp.connectionID

        self.remoteConnID = remoteConnID
        scccnAvp = L2tpv3RFC3931AVPs.ControlMessageAVP(
            L2tpv3RFC3931AVPs.ControlMessageAVP.SCCCN)
        scccn = L2tpv3ControlPacket.L2tpv3ControlPacket(
            self.remoteConnID, 0, 0, (scccnAvp, ))

        if len(pkt.avps) > 1:
            for i in xrange(1, len(pkt.avps)):
                avp = pkt.avps[i]
                # We got a bad ICRQ, we should send a CDN
                if not avp.handleAvp(pkt, scccn):
                    self.fsm.recvBadSCCRP()
                    return L2tpv3ControlPacket.L2tpv3StopCCN(
                        self, 2, 4, "Avp cannot handled correctly")

        self.fsm.recvGoodSCCRP()
        return scccn