-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@2272436 Backport subintf changes to co.fortcollins.eosdk.
- Loading branch information
Showing
12 changed files
with
367 additions
and
5 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
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,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 |
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,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 |
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,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 |
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
Oops, something went wrong.