Skip to content

Commit

Permalink
Merge "Implement attribute database for PmsiTunnel"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Feb 10, 2015
2 parents 76706a4 + 136d30f commit 98ff667
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 36 deletions.
25 changes: 19 additions & 6 deletions src/bgp/bgp_attr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ PmsiTunnelSpec::PmsiTunnelSpec(const BgpAttribute &rhs)
int PmsiTunnelSpec::CompareTo(const BgpAttribute &rhs_attr) const {
int ret = BgpAttribute::CompareTo(rhs_attr);
if (ret != 0) return ret;
const PmsiTunnelSpec &rhs =
static_cast<const PmsiTunnelSpec &>(rhs_attr);
KEY_COMPARE(this, &rhs);
const PmsiTunnelSpec &rhs = static_cast<const PmsiTunnelSpec &>(rhs_attr);
KEY_COMPARE(tunnel_flags, rhs.tunnel_flags);
KEY_COMPARE(tunnel_type, rhs.tunnel_type);
KEY_COMPARE(label, rhs.label);
KEY_COMPARE(identifier, rhs.identifier);
return 0;
}

Expand Down Expand Up @@ -207,15 +209,24 @@ void PmsiTunnelSpec::SetIdentifier(Ip4Address in_identifier) {
std::copy(bytes.begin(), bytes.begin() + 4, identifier.begin());
}

PmsiTunnel::PmsiTunnel(const PmsiTunnelSpec &pmsi_spec)
: pmsi_spec_(pmsi_spec) {
PmsiTunnel::PmsiTunnel(PmsiTunnelDB *pmsi_tunnel_db,
const PmsiTunnelSpec &pmsi_spec)
: pmsi_tunnel_db_(pmsi_tunnel_db),
pmsi_spec_(pmsi_spec) {
refcount_ = 0;
tunnel_flags = pmsi_spec_.tunnel_flags;
tunnel_type = pmsi_spec_.tunnel_type;
label = pmsi_spec_.GetLabel();
identifier = pmsi_spec_.GetIdentifier();
}

void PmsiTunnel::Remove() {
pmsi_tunnel_db_->Delete(this);
}

PmsiTunnelDB::PmsiTunnelDB(BgpServer *server) {
}

EdgeDiscoverySpec::EdgeDiscoverySpec()
: BgpAttribute(McastEdgeDiscovery, kFlags) {
}
Expand Down Expand Up @@ -590,7 +601,9 @@ void BgpAttr::set_origin_vn_path(const OriginVnPathSpec *spec) {

void BgpAttr::set_pmsi_tunnel(const PmsiTunnelSpec *pmsi_spec) {
if (pmsi_spec) {
pmsi_tunnel_.reset(new PmsiTunnel(*pmsi_spec));
pmsi_tunnel_ = attr_db_->server()->pmsi_tunnel_db()->Locate(*pmsi_spec);
} else {
pmsi_tunnel_ = NULL;
}
}

Expand Down
51 changes: 43 additions & 8 deletions src/bgp/bgp_attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,35 +223,70 @@ struct PmsiTunnelSpec : public BgpAttribute {

class PmsiTunnel {
public:
explicit PmsiTunnel(const PmsiTunnelSpec &pmsi_spec);
PmsiTunnel(PmsiTunnelDB *pmsi_tunnel_db, const PmsiTunnelSpec &pmsi_spec);
virtual ~PmsiTunnel() { }
virtual void Remove();
int CompareTo(const PmsiTunnel &rhs) const {
return pmsi_spec_.CompareTo(rhs.pmsi_tunnel());
}

const PmsiTunnelSpec &pmsi_tunnel() const { return pmsi_spec_; }

friend std::size_t hash_value(const PmsiTunnel &pmsi_tunnel) {
size_t hash = 0;
boost::hash_combine(hash, pmsi_tunnel.pmsi_tunnel().ToString());
return hash;
}

uint8_t tunnel_flags;
uint8_t tunnel_type;
uint32_t label;
Ip4Address identifier;

private:
friend void intrusive_ptr_add_ref(PmsiTunnel *pmsi_tunnel);
friend void intrusive_ptr_release(PmsiTunnel *pmsi_tunnel);
friend int intrusive_ptr_add_ref(const PmsiTunnel *cpmsi_tunnel);
friend int intrusive_ptr_del_ref(const PmsiTunnel *cpmsi_tunnel);
friend void intrusive_ptr_release(const PmsiTunnel *cpmsi_tunnel);

tbb::atomic<int> refcount_;
mutable tbb::atomic<int> refcount_;
PmsiTunnelDB *pmsi_tunnel_db_;
PmsiTunnelSpec pmsi_spec_;
};

inline void intrusive_ptr_add_ref(PmsiTunnel *pmsi_tunnel) {
pmsi_tunnel->refcount_.fetch_and_increment();
inline int intrusive_ptr_add_ref(const PmsiTunnel *cpmsi_tunnel) {
return cpmsi_tunnel->refcount_.fetch_and_increment();
}

inline void intrusive_ptr_release(PmsiTunnel *pmsi_tunnel) {
int prev = pmsi_tunnel->refcount_.fetch_and_decrement();
inline int intrusive_ptr_del_ref(const PmsiTunnel *cpmsi_tunnel) {
return cpmsi_tunnel->refcount_.fetch_and_decrement();
}

inline void intrusive_ptr_release(const PmsiTunnel *cpmsi_tunnel) {
int prev = cpmsi_tunnel->refcount_.fetch_and_decrement();
if (prev == 1) {
PmsiTunnel *pmsi_tunnel = const_cast<PmsiTunnel *>(cpmsi_tunnel);
pmsi_tunnel->Remove();
assert(pmsi_tunnel->refcount_ == 0);
delete pmsi_tunnel;
}
}

typedef boost::intrusive_ptr<PmsiTunnel> PmsiTunnelPtr;

struct PmsiTunnelCompare {
bool operator()(const PmsiTunnel *lhs, const PmsiTunnel *rhs) {
return lhs->CompareTo(*rhs) < 0;
}
};

class PmsiTunnelDB : public BgpPathAttributeDB<PmsiTunnel, PmsiTunnelPtr,
PmsiTunnelSpec,
PmsiTunnelCompare,
PmsiTunnelDB> {
public:
explicit PmsiTunnelDB(BgpServer *server);
};

struct EdgeDiscoverySpec : public BgpAttribute {
static const int kSize = -1;
static const uint8_t kFlags = Optional | Transitive;
Expand Down
1 change: 1 addition & 0 deletions src/bgp/bgp_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ BgpServer::BgpServer(EventManager *evm)
comm_db_(new CommunityDB(this)),
extcomm_db_(new ExtCommunityDB(this)),
ovnpath_db_(new OriginVnPathDB(this)),
pmsi_tunnel_db_(new PmsiTunnelDB(this)),
attr_db_(new BgpAttrDB(this)),
session_mgr_(BgpObjectFactory::Create<BgpSessionManager>(evm, this)),
sched_mgr_(new SchedulingGroupManager),
Expand Down
3 changes: 3 additions & 0 deletions src/bgp/bgp_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ExtCommunityDB;
class LifetimeActor;
class LifetimeManager;
class OriginVnPathDB;
class PmsiTunnelDB;
class PeerRibMembershipManager;
class RoutePathReplicator;
class RoutingInstanceMgr;
Expand Down Expand Up @@ -97,6 +98,7 @@ class BgpServer {
CommunityDB *comm_db() { return comm_db_.get(); }
ExtCommunityDB *extcomm_db() { return extcomm_db_.get(); }
OriginVnPathDB *ovnpath_db() { return ovnpath_db_.get(); }
PmsiTunnelDB *pmsi_tunnel_db() { return pmsi_tunnel_db_.get(); }

bool IsDeleted() const;
bool IsReadyForDeletion();
Expand Down Expand Up @@ -172,6 +174,7 @@ class BgpServer {
boost::scoped_ptr<CommunityDB> comm_db_;
boost::scoped_ptr<ExtCommunityDB> extcomm_db_;
boost::scoped_ptr<OriginVnPathDB> ovnpath_db_;
boost::scoped_ptr<PmsiTunnelDB> pmsi_tunnel_db_;
boost::scoped_ptr<BgpAttrDB> attr_db_;

// sessions and state managers
Expand Down

0 comments on commit 98ff667

Please sign in to comment.