Ejemplo n.º 1
0
    def keepalive_received(self, timestamp, msg):
        """
        process keepalive message

        :param timestamp:
        :param msg:
        :return:
        """
        self.msg_recv_stat['Keepalives'] += 1

        if self.msg_recv_stat['Keepalives'] == 1:
            # agent online
            if not CONF.standalone and self.factory.tag in \
                    [channel_cons.TARGET_ROUTER_TAG, channel_cons.SOURCE_AND_TARGET_ROUTER_TAG]:
                send_to_channel_msg = {
                    'agent_id': '%s:%s' % (CONF.rest.bind_host, CONF.rest.bind_port),
                    'type': bgp_cons.MSG_KEEPALIVE,
                    'msg': None
                }
                self.factory.channel.send_message(
                    exchange='', routing_key=self.factory.peer_addr, message=send_to_channel_msg)

        LOG.info("[%s]A BGP KeepAlive message was received from peer.", self.factory.peer_addr)
        KeepAlive().parse(msg)

        if CONF.message.write_keepalive:
            # write bgp message
            self.factory.write_msg(
                timestamp=timestamp,
                msg_type=4,
                msg={"msg": None},
                flush=True
            )
        self.fsm.keep_alive_received()
Ejemplo n.º 2
0
    def _keepalive_received(self, timestamp, msg):
        """
            process keepalive message

            :param timestamp:
            :param msg:
            :return:
        """

        # deal with all request in internal message queue
        # until the queue is empty
        while not self.handler.inter_mq.empty(
        ) and self.msg_recv_stat['Keepalives'] > 0:
            inter_msg = self.handler.inter_mq.get()
            LOG.debug('Get %s message %s from internal queue',
                      inter_msg['type'], inter_msg['msg'])
            if inter_msg['type'] == 'notification':
                self.send_notification(inter_msg['msg']['error'],
                                       inter_msg['msg']['sub_error'],
                                       inter_msg['msg']['data'])
            elif inter_msg['type'] == 'update':
                self.send_update(inter_msg['msg'])

        self.msg_recv_stat['Keepalives'] += 1

        self.handler.keepalive_received(self, timestamp)

        LOG.info("[%s]A BGP KeepAlive message was received from peer.",
                 self.factory.peer_addr)
        KeepAlive().parse(msg)

        self.fsm.keep_alive_received()
Ejemplo n.º 3
0
 def send_keepalive(self):
     """
     send BGP keepalive message.
     """
     self.msg_sent_stat['Keepalives'] += 1
     LOG.info("[%s]Send a BGP KeepAlive message to the peer.", self.factory.peer_addr)
     # message statistci
     # self.msg_sent_stat['Keepalives'] += 1
     # construct message
     msg_keepalive = KeepAlive().construct()
     # send message
     self.transport.write(msg_keepalive)
Ejemplo n.º 4
0
    def keepalive_received(self, timestamp, msg):
        """
        process keepalive message

        :param timestamp:
        :param msg:
        :return:
        """
        self.msg_recv_stat['Keepalives'] += 1
        LOG.info("[%s]A BGP KeepAlive message was received from peer.", self.factory.peer_addr)
        KeepAlive().parse(msg)

        if CONF.message.write_keepalive:
            # write bgp message
            self.factory.write_msg(
                timestamp=timestamp,
                msg_type=4,
                msg=None,
                flush=True
            )
        self.fsm.keep_alive_received()
Ejemplo n.º 5
0
    def test_construct(self):

        msg_hex = KeepAlive().construct()
        hope_msg = b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04'
        self.assertEqual(hope_msg, msg_hex)
Ejemplo n.º 6
0
 def test_parse_msg_header_error(self):
     self.assertRaises(MessageHeaderError, KeepAlive().parse, b'\x00')
Ejemplo n.º 7
0
 def test_parse(self):
     msg_hex = ''
     keepalive_msg = KeepAlive().parse(msg_hex)
     self.assertEqual(None, keepalive_msg)