OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vxlan_templates.cc
Go to the documentation of this file.
1 template <class ItType>
2 std::vector<IpAddress> VxlanRoutingManager::ItemNexthopsToVector(ItType *item) {
3  std::vector<IpAddress> nh_addr;
4  const uint32_t n_items = item->entry.next_hops.next_hop.size();
5  for (uint32_t i_nh=0; i_nh < n_items; i_nh++) {
6  const IpAddress nh_ip = IpAddress::from_string(
7  item->entry.next_hops.next_hop[i_nh].address);
8  nh_addr.insert(nh_addr.end(), nh_ip);
9  }
10 
11  return nh_addr;
12 }
13 
14 template<typename NhType>
16  const std::string& prefix_str,
17  const std::string& vrf_name,
18  const NhType &nh_item,
19  ComponentNHKeyList& comp_nh_list) {
20  const Agent *agent = Agent::GetInstance();
21  IpAddress ip_addr;
22  uint32_t prefix_len;
23  boost::system::error_code ec;
24 
25  if (is_ipv4_string(prefix_str)) {
26  ip_addr = Ip4Address::from_string(ipv4_prefix(prefix_str), ec);
27  prefix_len = ipv4_prefix_len(prefix_str);
28  } else if (is_ipv6_string(prefix_str)) {
29  std::string addr_str = ipv6_prefix(prefix_str);
30  prefix_len = ipv6_prefix_len(prefix_str);
31  ip_addr = Ip6Address::from_string(addr_str, ec);
32  } else {
33  LOG(ERROR, "Error in VxlanRoutingManager::AddInterfaceComponentToList"
34  << ", prefix_str = " << prefix_str
35  << " is not an IPv4 or IPv6 prefix");
36  return;
37  }
38 
39  if (ec) {
40  LOG(ERROR, "Possible error in "
41  << "VxlanRoutingManager::AddInterfaceComponentToList"
42  << ", cannot convert prefix_str = " << prefix_str
43  << " to IPv4 or IPv6 address");
44  return;
45  }
46 
47  const AgentRoute *intf_rt =
48  FindEvpnOrInetRoute(agent, vrf_name, ip_addr, prefix_len, nh_item);
49  if (intf_rt == NULL) {
50  return;
51  }
52 
53  const AgentPath *loc_path =
55  if (loc_path == NULL) {
56  return;
57  }
58  if (loc_path->nexthop() == NULL) {
59  return;
60  }
61 
62  // Case 1. NextHop is an interface
63  if (loc_path->nexthop()->GetType() == NextHop::INTERFACE) {
64  DBEntryBase::KeyPtr key_ptr =
65  loc_path->nexthop()->GetDBRequestKey();
66  NextHopKey *nh_key =
67  static_cast<NextHopKey *>(key_ptr.release());
68  std::unique_ptr<const NextHopKey> nh_key_ptr(nh_key);
69  ComponentNHKeyPtr component_nh_key(new ComponentNHKey(MplsTable::kInvalidLabel, // label
70  std::move(nh_key_ptr)));
71  comp_nh_list.push_back(component_nh_key);
72  return;
73  }
74 
75  // Case 2. NextHop is a composite of interfaces
76  // Copy all interfaces from this composite
77  // into the components list
78  if (loc_path->nexthop()->GetType() == NextHop::COMPOSITE) {
79  CompositeNH *loc_comp_nh = dynamic_cast<CompositeNH*>
80  (loc_path->nexthop());
81 
82  DBEntryBase::KeyPtr key_ptr =
83  loc_comp_nh->GetDBRequestKey();
84  CompositeNHKey *nh_key =
85  static_cast<CompositeNHKey *>(key_ptr.release());
86  std::unique_ptr<const NextHopKey> nh_key_ptr(nh_key);
87 
88  if (nh_key == NULL){
89  LOG(ERROR, "Error in VxlanRoutingManager::AddInterfaceComponentToList"
90  << ", null nh key");
91  assert(nh_key != NULL);
92  }
93 
94  // Refresh on path_preference.sequence change
95  const ComponentNHList& component_nh_list =
96  loc_comp_nh->component_nh_list();
97  for (ComponentNHList::const_iterator
98  it_nh = component_nh_list.begin();
99  it_nh != component_nh_list.end(); it_nh++) {
100  // nullptr means deleted component, which
101  // can be reused later
102  std::unique_ptr<const NextHopKey> nh_key_ptr;
103  ComponentNHKeyPtr component_nh_key;
104  if (it_nh->get() == NULL) {
105  // component_nh_key.reset(NULL);
106  } else {
107  DBEntryBase::KeyPtr key =
108  it_nh->get()->nh()->GetDBRequestKey();
109  NextHopKey *nh_key =
110  static_cast<NextHopKey *>(key.release());
111  nh_key_ptr.reset(nh_key);
112  component_nh_key.reset(
113  new ComponentNHKey(MplsTable::kInvalidLabel, std::move(nh_key_ptr)));
114  }
115  comp_nh_list.push_back(component_nh_key);
116  }
117  }
118 } // AddInterfaceComponentToList func
119 
120 //
121 // END-OF-FILE
122 //
static Agent * GetInstance()
Definition: agent.h:436
static uint32_t ipv4_prefix_len(const std::string &prefix_str)
Extracts length of IPv4 subnet address from the prefix string.
static std::string ipv4_prefix(const std::string &prefix_str)
Extracts an IPv4 address string from the prefix string.
boost::asio::ip::address IpAddress
Definition: address.h:13
boost::shared_ptr< const ComponentNHKey > ComponentNHKeyPtr
Definition: nexthop.h:1639
static AgentRoute * FindEvpnOrInetRoute(const Agent *agent, const std::string &vrf_name, const IpAddress &ip_addr, uint32_t prefix_len, const autogen::EnetNextHopType &nh_item)
Finds a route with the given prefix address and len in the EVPN table.
static bool is_ipv4_string(const std::string &prefix_str)
Determines whether the address string contains an IPv4 address as substring or not.
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
Type GetType() const
Definition: nexthop.h:405
Base class for all Route entries in agent.
Definition: agent_route.h:224
std::vector< ComponentNHKeyPtr > ComponentNHKeyList
Definition: nexthop.h:1641
static std::vector< IpAddress > ItemNexthopsToVector(ItType *item)
Templates.
NextHop * nexthop() const
Definition: agent_path.cc:87
static void AddInterfaceComponentToList(const std::string &prefix_str, const std::string &vrf_name, const NhType &nh_item, ComponentNHKeyList &comp_nh_list)
Adds an interface or a composite of interfaces nexthops to the list of components NH keys needed for ...
static bool is_ipv6_string(const std::string &prefix_str)
Determines whether the address string contains an IPv6 address as substring or not.
Definition: agent.h:358
const ComponentNHList & component_nh_list() const
Definition: nexthop.h:1869
virtual KeyPtr GetDBRequestKey() const =0
static const uint32_t kInvalidLabel
Definition: mpls.h:101
const AgentPath * FindIntfOrCompLocalVmPortPath() const
Finds path to an interface or a composite of interfaces and returns it. The priority is given to comp...
Definition: agent_route.cc:816
static uint32_t ipv6_prefix_len(const std::string &prefix_str)
Extracts length of IPv6 subnet address from the prefix string.
#define LOG(_Level, _Msg)
Definition: logging.h:33
std::vector< ComponentNHPtr > ComponentNHList
Definition: nexthop.h:1637
static std::string ipv6_prefix(const std::string &prefix_str)
Extracts an IPv6 address string from the prefix string.
virtual KeyPtr GetDBRequestKey() const
Definition: nexthop.cc:2183