LCOV - code coverage report
Current view: top level - bgp - xmpp_message_builder.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 7 7 100.0 %
Date: 2026-11-09 02:10:49 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #ifndef SRC_BGP_XMPP_MESSAGE_BUILDER_H_
       7             : #define SRC_BGP_XMPP_MESSAGE_BUILDER_H_
       8             : 
       9             : #include <pugixml/pugixml.hpp>
      10             : 
      11             : #include <string>
      12             : #include <vector>
      13             : 
      14             : #include "bgp/message_builder.h"
      15             : #include "bgp/bgp_ribout.h"
      16             : #include "bgp/extended-community/load_balance.h"
      17             : 
      18             : namespace autogen {
      19             : class ItemType;
      20             : class EnetItemType;
      21             : }
      22             : class Community;
      23             : class ExtCommunity;
      24             : 
      25             : class BgpXmppMessageBuilder : public MessageBuilder {
      26             : public:
      27             :     BgpXmppMessageBuilder();
      28             :     virtual Message *Create() const;
      29             : 
      30             : private:
      31             :     DISALLOW_COPY_AND_ASSIGN(BgpXmppMessageBuilder);
      32             : };
      33             : 
      34             : class BgpXmppMessage : public Message {
      35             : public:
      36             :     BgpXmppMessage();
      37             :     virtual ~BgpXmppMessage();
      38             : 
      39             :     virtual bool Start(const RibOut *ribout, bool cache_routes,
      40             :                        const RibOutAttr *roattr, const BgpRoute *route);
      41             :     virtual void Finish();
      42             :     virtual bool AddRoute(const BgpRoute *route, const RibOutAttr *roattr);
      43             :     virtual const uint8_t *GetData(IPeerUpdate *peer, size_t *lenp,
      44             :                                    const std::string **msg_str,
      45             :                                    std::string *temp);
      46             : 
      47             : private:
      48             :     static const size_t kMaxFromToLength = 192;
      49             :     static const uint32_t kMaxReachCount = 32;
      50             :     static const uint32_t kMaxUnreachCount = 256;
      51             : 
      52             :     class XmlWriter : public pugi::xml_writer {
      53             :     public:
      54         144 :         explicit XmlWriter(std::string *repr) : repr_(repr) { }
      55      740051 :         virtual void write(const void *data, size_t size) {
      56      740051 :             repr_->append(static_cast<const char*>(data), size);
      57      740049 :         }
      58             : 
      59             :     private:
      60             :         std::string *repr_;
      61             :     };
      62             : 
      63             :     struct MobilityInfo {
      64             :     public:
      65         144 :         MobilityInfo(uint32_t seqno, bool sticky)
      66         144 :             : sequence_number(seqno), sticky(sticky) {
      67         144 :         }
      68             :         uint32_t sequence_number;
      69             :         bool sticky;
      70             :     };
      71             : 
      72             :     virtual void Reset();
      73             :     void EncodeNextHop(const BgpRoute *route,
      74             :                        const RibOutAttr::NextHop &nexthop,
      75             :                        autogen::ItemType *item);
      76             :     void AddIpReach(const BgpRoute *route, const RibOutAttr *roattr);
      77             :     void AddIpUnreach(const BgpRoute *route);
      78             :     bool AddInetRoute(const BgpRoute *route, const RibOutAttr *roattr);
      79             : 
      80             :     bool AddInet6Route(const BgpRoute *route, const RibOutAttr *roattr);
      81             : 
      82             :     void EncodeEnetNextHop(const BgpRoute *route,
      83             :                            const RibOutAttr::NextHop &nexthop,
      84             :                            autogen::EnetItemType *item);
      85             :     void AddEnetReach(const BgpRoute *route, const RibOutAttr *roattr);
      86             :     void AddEnetUnreach(const BgpRoute *route);
      87             :     bool AddEnetRoute(const BgpRoute *route, const RibOutAttr *roattr);
      88             : 
      89             :     void AddMcastReach(const BgpRoute *route, const RibOutAttr *roattr);
      90             :     void AddMcastUnreach(const BgpRoute *route);
      91             :     bool AddMcastRoute(const BgpRoute *route, const RibOutAttr *roattr);
      92             : 
      93             :     void AddMvpnReach(const BgpRoute *route, const RibOutAttr *roattr);
      94             :     void AddMvpnUnreach(const BgpRoute *route);
      95             :     bool AddMvpnRoute(const BgpRoute *route, const RibOutAttr *roattr);
      96             : 
      97             :     void ProcessCommunity(const Community *community);
      98             :     void ProcessExtCommunity(const ExtCommunity *ext_community);
      99             :     std::string GetVirtualNetwork(const RibOutAttr::NextHop &nexthop) const;
     100             :     std::string GetVirtualNetwork(const BgpRoute *route,
     101             :                                   const RibOutAttr *roattr) const;
     102             : 
     103             :     const BgpTable *table_;
     104             :     XmlWriter writer_;
     105             :     bool is_reachable_;
     106             :     bool cache_routes_;
     107             :     bool repr_valid_;
     108             :     std::string msg_begin_;
     109             :     std::string repr_;
     110             :     pugi::xml_document doc_;
     111             :     MobilityInfo mobility_;
     112             :     bool etree_leaf_;
     113             : 
     114             :     std::vector<int> security_group_list_;
     115             :     std::vector<std::string> community_list_;
     116             :     LoadBalance::LoadBalanceAttribute load_balance_attribute_;
     117             : 
     118             :     DISALLOW_COPY_AND_ASSIGN(BgpXmppMessage);
     119             : };
     120             : 
     121             : #endif  // SRC_BGP_XMPP_MESSAGE_BUILDER_H_

Generated by: LCOV version 1.14