Skip to content

Commit

Permalink
@2272436 Backport subintf changes to co.fortcollins.eosdk.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmadsen authored and tsuna committed Feb 15, 2015
1 parent de3062f commit 0393829
Show file tree
Hide file tree
Showing 12 changed files with 367 additions and 5 deletions.
4 changes: 4 additions & 0 deletions EosSdk.i
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef uint64_t uint64_be_t;
%feature("nodirector") eos::neighbor_table_mgr;
%feature("nodirector") eos::nexthop_group_mgr;
%feature("nodirector") eos::policy_map_mgr;
%feature("nodirector") eos::subintf_mgr;
%feature("nodirector") eos::system_mgr;
%feature("nodirector") eos::timeout_mgr;
%feature("nodirector") eos::vrf_mgr;
Expand Down Expand Up @@ -90,6 +91,7 @@ typedef uint64_t uint64_be_t;
#include "eos/mpls_route.h"
#include "eos/policy_map.h"
#include "eos/sdk.h"
#include "eos/subintf.h"
#include "eos/system.h"
#include "eos/timer.h"
#include "eos/tracing.h"
Expand Down Expand Up @@ -245,10 +247,12 @@ wrap_iterator(eos::mpls_route_iter_t, eos::mpls_route_iter_impl, eos::mpls_route
wrap_iterator(eos::mpls_route_via_iter_t, eos::mpls_route_via_iter_impl, eos::mpls_route_via_t);
wrap_iterator(eos::nexthop_group_iter_t, eos::nexthop_group_iter_impl, eos::nexthop_group_t);
wrap_iterator(eos::policy_map_iter_t, eos::policy_map_iter_impl, eos::policy_map_key_t);
wrap_iterator(eos::subintf_iter_t, eos::subintf_iter_impl, eos::intf_id_t);
wrap_iterator(eos::vrf_iter_t, eos::vrf_iter_impl, eos::vrf_t);

// Make managers themselves iterable, when it makes sense:
default_iterator(eos::directflow_mgr, flow_entry_iter);
default_iterator(eos::intf_mgr, intf_iter);
default_iterator(eos::ip_route_mgr, ip_route_iter);
default_iterator(eos::mpls_route_mgr, mpls_route_iter);
default_iterator(eos::subintf_mgr, subintf_iter);
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ libeos_la_SOURCES += neighbor_table.cpp
libeos_la_SOURCES += policy_map.cpp
libeos_la_SOURCES += policy_map_types.cpp
libeos_la_SOURCES += sdk.cpp
libeos_la_SOURCES += subintf.cpp
libeos_la_SOURCES += system.cpp
libeos_la_SOURCES += timer.cpp
libeos_la_SOURCES += tracing.cpp
Expand Down
7 changes: 7 additions & 0 deletions eos/inline/sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ inline policy_map_mgr * sdk::get_policy_map_mgr() {
return policy_map_mgr_;
}

inline subintf_mgr * sdk::get_subintf_mgr() {
if (!subintf_mgr_) {
init_subintf_mgr();
}
return subintf_mgr_;
}

inline system_mgr * sdk::get_system_mgr() {
if (!system_mgr_) {
init_system_mgr();
Expand Down
74 changes: 74 additions & 0 deletions eos/inline/types/subintf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) 2015 Arista Networks, Inc. All rights reserved.
// Arista Networks, Inc. Confidential and Proprietary.

#ifndef EOS_INLINE_TYPES_SUBINTF_H
#define EOS_INLINE_TYPES_SUBINTF_H

namespace eos {

// Default constructor.
inline subintf_t::subintf_t() :
intf_id_(intf_id_t()), vlan_id_(vlan_id_t()) {
}

inline subintf_t::subintf_t(intf_id_t intf_id, vlan_id_t vlan_id) :
intf_id_(intf_id), vlan_id_(vlan_id) {
}

inline intf_id_t
subintf_t::intf_id() const {
return intf_id_;
}

inline vlan_id_t
subintf_t::vlan_id() const {
return vlan_id_;
}

inline void
subintf_t::vlan_id_is(vlan_id_t vlan_id) {
vlan_id_ = vlan_id;
}

inline bool
subintf_t::operator==(subintf_t const & other) const {
return intf_id_ == other.intf_id_ &&
vlan_id_ == other.vlan_id_;
}

inline bool
subintf_t::operator!=(subintf_t const & other) const {
return !operator==(other);
}

inline uint32_t
subintf_t::hash() const {
uint32_t ret = 0;
ret = hash_mix::mix((uint8_t *)&intf_id_,
sizeof(intf_id_t), ret);
ret = hash_mix::mix((uint8_t *)&vlan_id_,
sizeof(vlan_id_t), ret);
ret = hash_mix::final_mix(ret);
return ret;
}

inline std::string
subintf_t::to_string() const {
std::ostringstream ss;
ss << "subintf_t(";
ss << "intf_id=" << intf_id_.to_string();
ss << ", vlan_id=" << vlan_id_;
ss << ")";
return ss.str();
}

inline std::ostream&
operator<<(std::ostream& os, const subintf_t& obj) {
os << obj.to_string();
return os;
}


}

#endif // EOS_INLINE_TYPES_SUBINTF_H
5 changes: 4 additions & 1 deletion eos/sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class mpls_route_mgr;
class neighbor_table_mgr;
class nexthop_group_mgr;
class policy_map_mgr;
class subintf_mgr;
class system_mgr;
class timeout_mgr;
class vrf_mgr;
Expand Down Expand Up @@ -145,6 +146,7 @@ class EOS_SDK_PUBLIC sdk {
virtual void init_neighbor_table_mgr();
virtual void init_nexthop_group_mgr();
virtual void init_policy_map_mgr();
virtual void init_subintf_mgr();
virtual void init_system_mgr();
virtual void init_timeout_mgr();
virtual void init_vrf_mgr();
Expand All @@ -167,12 +169,12 @@ class EOS_SDK_PUBLIC sdk {
virtual ip_route_mgr * get_ip_route_mgr();
virtual mac_table_mgr * get_mac_table_mgr();
virtual mlag_mgr * get_mlag_mgr();
// TODO: move back to private (BUG86400)
virtual mount_mgr * get_mount_mgr();
virtual mpls_route_mgr * get_mpls_route_mgr();
virtual neighbor_table_mgr * get_neighbor_table_mgr();
virtual nexthop_group_mgr * get_nexthop_group_mgr();
virtual policy_map_mgr * get_policy_map_mgr();
virtual subintf_mgr * get_subintf_mgr();
virtual system_mgr * get_system_mgr();
virtual timeout_mgr * get_timeout_mgr();
virtual vrf_mgr * get_vrf_mgr();
Expand Down Expand Up @@ -204,6 +206,7 @@ class EOS_SDK_PUBLIC sdk {
neighbor_table_mgr * neighbor_table_mgr_;
nexthop_group_mgr * nexthop_group_mgr_;
policy_map_mgr * policy_map_mgr_;
subintf_mgr * subintf_mgr_;
system_mgr * system_mgr_;
timeout_mgr * timeout_mgr_;
vrf_mgr * vrf_mgr_;
Expand Down
159 changes: 159 additions & 0 deletions eos/subintf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// Copyright (c) 2014 Arista Networks, Inc. All rights reserved.
// Arista Networks, Inc. Confidential and Proprietary.

/**
* @file
* The subintf module manages subinterfaces.
*
* Subinterfaces are multiple logical routed interfaces under an Ethernet or
* LAG routed interface (also referred to as the parent interface). Each
* subinterface is assigned a VLAN tag that is unique to the subinterface
* (among all its sibling subinterfaces under the same parent interface). The
* VLAN tag is used for mux/demux of data traffic from/to all subinterfaces
* under the parent interface.
*
* This module provides APIs to provision subinterfaces. APIs include subinterface
* creation, deletion, retrieval and getter/setter for the subinterface VLAN tag.
* An iterator is also provided to iterate through all the subinterfaces that are
* configured in the system.
*
* The subinterface APIs can be used with the ones in "intf" module, as shown
* in the sample code below. For example, the eos::intf_handler's on_intf_create()
* API can be used to react to the creation of new subinterfaces.
*
* @code
*
#include <eos/agent.h>
#include <eos/subintf.h>
#include <eos/panic.h>
#include <eos/sdk.h>
static eos::subintf_mgr *subintf_mgr;
class ApplicationAgent : public eos::agent_handler, eos::intf_handler {
public:
explicit ApplicationAgent(eos::sdk & sdk) :
eos::agent_handler(sdk.get_agent_mgr()),
eos::intf_handler(sdk.get_intf_mgr()) {
watch_intf(eos::intf_id_t("Ethernet1.1"), true);
}
// Called when all agents are initialized
void on_initialized() {
// Creates subinterface
subintf_mgr->subintf_is(eos::intf_id_t("Ethernet1.1"));
}
// Handler for subinterface creation
void on_intf_create(eos::intf_id_t i) {
if (i == eos::intf_id_t("Ethernet1.1")) {
// Ethernet1.1 is now usable.
// Other application logic goes here, such as creating more subinterfaces
}
return;
}
}
int main(int argc, char **argv) {
eos::sdk sdk;
subintf_mgr = sdk.get_subintf_mgr();
ApplicationAgent agent(sdk);
sdk.main_loop(argc, argv);
}
* @endcode
*/


#ifndef EOS_SUBINTF_H
#define EOS_SUBINTF_H

#include <eos/intf.h>
#include <eos/iterator.h>
#include <eos/types/subintf.h>

namespace eos {

class subintf_iter_impl;

/**
* An iterator over all subinterfaces in the system.
*/
class EOS_SDK_PUBLIC subintf_iter_t : public iter_base<intf_id_t,
subintf_iter_impl> {
private:
explicit subintf_iter_t(subintf_iter_impl * const) EOS_SDK_PRIVATE;
friend class subintf_iter_impl;
};

/**
* The manager for subinterfaces. This is the main entry point for applications
* to use EosSdk subintf APIs.
*/
class EOS_SDK_PUBLIC subintf_mgr {
public:
virtual ~subintf_mgr();

/**
* Returns an iterator for iterating over the subinterfaces in the system.
* The iterator yields an intf_id_t for each configured subinterface.
*/
virtual subintf_iter_t subintf_iter() const = 0;

/**
* Creates a subinterface when given the subinterface ID.
* No action will be taken if the subinterface exists already.
* The subinterface will be created even if its parent interface does not exist.
* But the subinterface will become operationally up on only after its parent
* interface becomes operationally up and is in routed mode.
*/
virtual void subintf_is(intf_id_t) = 0;

/**
* Creates a subinterface and sets its VLAN tag. If the subinterface already
* exists, its VLAN tag will be updated.
*/
virtual void subintf_is(intf_id_t, vlan_id_t) = 0;

/**
* Returns the subinterface with the given ID.
* Will return an empty subintf_t if the subinterface does not exist.
*/
virtual subintf_t subintf(intf_id_t) const = 0;

/**
* Deletes a subinterface. It will simply return if the given subinterface
* does not exist.
*/
virtual void subintf_del(intf_id_t) = 0;

/**
* Returns the configured VLAN tag of a given subinterface. Returns zero if
* the subinterface does not exist or if no VLAN tag is configured for the
* subinterface.
*/
virtual vlan_id_t vlan_tag(intf_id_t) const = 0;

/**
* Configures the VLAN tag of a given subinterface. Throws
* invalid_argument_error exception if the subinterface does not exist.
*/
virtual void vlan_tag_is(intf_id_t, vlan_id_t) = 0;

/**
* Returns the parent interface ID for a given subinterface. The parent
* interface will be an Ethernet or a LAG interface.
* Returns an empty intf_id_t (with intf_type as INTF_TYPE_NULL), if the given
* interface is not a subinterface.
*/
virtual intf_id_t parent_intf(intf_id_t) const = 0;

protected:
subintf_mgr() EOS_SDK_PRIVATE;

private:
EOS_SDK_DISALLOW_COPY_CTOR(subintf_mgr);
};

}

#endif // EOS_SUBINTF_H
2 changes: 2 additions & 0 deletions eos/types/intf.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class EOS_SDK_PUBLIC intf_id_t {

/** Returns true if the interface is Null0. */
bool is_null0() const;
/** Returns true if the interface is a subinterface. */
bool is_subintf() const;
/** Returns the interface's type. */
intf_type_t intf_type() const;

Expand Down
49 changes: 49 additions & 0 deletions eos/types/subintf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2015 Arista Networks, Inc. All rights reserved.
// Arista Networks, Inc. Confidential and Proprietary.

#ifndef EOS_TYPES_SUBINTF_H
#define EOS_TYPES_SUBINTF_H

#include <eos/hash_mix.h>
#include <eos/types/eth.h>
#include <eos/types/intf.h>
#include <eos/utility.h>
#include <sstream>

namespace eos {

/** This data structure defines a subinterface. */
class EOS_SDK_PUBLIC subintf_t {
public:
subintf_t();
subintf_t(intf_id_t intf_id, vlan_id_t vlan_id);

/** Getter for 'intf_id': the interface ID of this subinterface. */
intf_id_t intf_id() const;

/** Getter for 'vlan_id': the VLAN tag of this subinterface. */
vlan_id_t vlan_id() const;
/** Setter for 'vlan_id'. */
void vlan_id_is(vlan_id_t vlan_id);

bool operator==(subintf_t const & other) const;
bool operator!=(subintf_t const & other) const;
/** The hash function for type subintf_t. */
uint32_t hash() const;
/** Returns a string representation of the current object's values. */
std::string to_string() const;
/**
* A utility stream operator that adds a string representation of subintf_t to
* the ostream.
*/
friend std::ostream& operator<<(std::ostream& os, const subintf_t& obj);

private:
intf_id_t intf_id_;
vlan_id_t vlan_id_;
};
}

#include <eos/inline/types/subintf.h>

#endif // EOS_TYPES_SUBINTF_H
5 changes: 5 additions & 0 deletions intf_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ intf_id_t::is_null0() const {
return false;
}

bool
intf_id_t::is_subintf() const {
return false;
}

intf_type_t
intf_id_t::intf_type() const {
return INTF_TYPE_NULL;
Expand Down
Loading

0 comments on commit 0393829

Please sign in to comment.