-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. create separate file for NextHopKey and NextHopGroupKey 2. remove test_AclRuleRedirectToNexthop
- Loading branch information
Tyler Li
committed
Sep 20, 2019
1 parent
06ab194
commit 698d10a
Showing
5 changed files
with
195 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#ifndef SWSS_NEXTHOPGROUPKEY_H | ||
#define SWSS_NEXTHOPGROUPKEY_H | ||
|
||
#include "nexthopkey.h" | ||
|
||
class NextHopGroupKey | ||
{ | ||
public: | ||
NextHopGroupKey() = default; | ||
|
||
/* ip_string|if_alias separated by ',' */ | ||
NextHopGroupKey(const std::string &nexthops) | ||
{ | ||
auto nhv = tokenize(nexthops, ','); | ||
for (const auto &nh : nhv) | ||
{ | ||
m_nexthops.insert(nh); | ||
} | ||
} | ||
|
||
inline const std::set<NextHopKey> &getNextHops() const | ||
{ | ||
return m_nexthops; | ||
} | ||
|
||
inline size_t getSize() const | ||
{ | ||
return m_nexthops.size(); | ||
} | ||
|
||
inline bool operator<(const NextHopGroupKey &o) const | ||
{ | ||
return m_nexthops < o.m_nexthops; | ||
} | ||
|
||
inline bool operator==(const NextHopGroupKey &o) const | ||
{ | ||
return m_nexthops == o.m_nexthops; | ||
} | ||
|
||
inline bool operator!=(const NextHopGroupKey &o) const | ||
{ | ||
return !(*this == o); | ||
} | ||
|
||
void add(const std::string &ip, const std::string &alias) | ||
{ | ||
m_nexthops.emplace(ip, alias); | ||
} | ||
|
||
void add(const std::string &nh) | ||
{ | ||
m_nexthops.insert(nh); | ||
} | ||
|
||
void add(const NextHopKey &nh) | ||
{ | ||
m_nexthops.insert(nh); | ||
} | ||
|
||
bool contains(const std::string &ip, const std::string &alias) const | ||
{ | ||
NextHopKey nh(ip, alias); | ||
return m_nexthops.find(nh) != m_nexthops.end(); | ||
} | ||
|
||
bool contains(const std::string &nh) const | ||
{ | ||
return m_nexthops.find(nh) != m_nexthops.end(); | ||
} | ||
|
||
bool contains(const NextHopKey &nh) const | ||
{ | ||
return m_nexthops.find(nh) != m_nexthops.end(); | ||
} | ||
|
||
bool contains(const NextHopGroupKey &nhs) const | ||
{ | ||
for (const auto &nh : nhs.getNextHops()) | ||
{ | ||
if (!contains(nh)) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
void remove(const std::string &ip, const std::string &alias) | ||
{ | ||
NextHopKey nh(ip, alias); | ||
m_nexthops.erase(nh); | ||
} | ||
|
||
void remove(const std::string &nh) | ||
{ | ||
m_nexthops.erase(nh); | ||
} | ||
|
||
void remove(const NextHopKey &nh) | ||
{ | ||
m_nexthops.erase(nh); | ||
} | ||
|
||
const std::string to_string() const | ||
{ | ||
string nhs_str; | ||
|
||
for (auto it = m_nexthops.begin(); it != m_nexthops.end(); ++it) | ||
{ | ||
if (it != m_nexthops.begin()) | ||
{ | ||
nhs_str += ","; | ||
} | ||
|
||
nhs_str += it->to_string(); | ||
} | ||
|
||
return nhs_str; | ||
} | ||
|
||
private: | ||
std::set<NextHopKey> m_nexthops; | ||
}; | ||
|
||
#endif /* SWSS_NEXTHOPGROUPKEY_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#ifndef SWSS_NEXTHOPKEY_H | ||
#define SWSS_NEXTHOPKEY_H | ||
|
||
#include "ipaddress.h" | ||
#include "tokenize.h" | ||
|
||
#define VRF_PREFIX "Vrf" | ||
extern IntfsOrch *gIntfsOrch; | ||
|
||
struct NextHopKey | ||
{ | ||
IpAddress ip_address; // neighbor IP address | ||
string alias; // incoming interface alias | ||
|
||
NextHopKey() = default; | ||
NextHopKey(const std::string &ipstr, const std::string &alias) : ip_address(ipstr), alias(alias) {} | ||
NextHopKey(const IpAddress &ip, const std::string &alias) : ip_address(ip), alias(alias) {} | ||
NextHopKey(const std::string &str) | ||
{ | ||
if (str.find(',') != string::npos) | ||
{ | ||
std::string err = "Error converting " + str + " to NextHop"; | ||
throw std::invalid_argument(err); | ||
} | ||
auto keys = tokenize(str, '|'); | ||
if (keys.size() == 1) | ||
{ | ||
ip_address = keys[0]; | ||
alias = gIntfsOrch->getRouterIntfsAlias(ip_address); | ||
} | ||
else if (keys.size() == 2) | ||
{ | ||
ip_address = keys[0]; | ||
alias = keys[1]; | ||
if (!alias.compare(0, strlen(VRF_PREFIX), VRF_PREFIX)) | ||
{ | ||
alias = gIntfsOrch->getRouterIntfsAlias(ip_address, alias); | ||
} | ||
} | ||
else | ||
{ | ||
std::string err = "Error converting " + str + " to NextHop"; | ||
throw std::invalid_argument(err); | ||
} | ||
} | ||
const std::string to_string() const | ||
{ | ||
return ip_address.to_string() + "|" + alias; | ||
} | ||
|
||
bool operator<(const NextHopKey &o) const | ||
{ | ||
return tie(ip_address, alias) < tie(o.ip_address, o.alias); | ||
} | ||
|
||
bool operator==(const NextHopKey &o) const | ||
{ | ||
return (ip_address == o.ip_address) && (alias == o.alias); | ||
} | ||
|
||
bool operator!=(const NextHopKey &o) const | ||
{ | ||
return !(*this == o); | ||
} | ||
}; | ||
|
||
#endif /* SWSS_NEXTHOPKEY_H */ |
Oops, something went wrong.