subintf

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.

   #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);
   }

namespace eos
class subintf_iter_t
#include <subintf.h>

An iterator over all subinterfaces in the system.

Private Functions

subintf_iter_t(subintf_iter_impl * const)

Friends

friend class subintf_iter_impl
class subintf_mgr
#include <subintf.h>

The manager for subinterfaces. This is the main entry point for applications to use EosSdk subintf APIs.

Public Functions

virtual ~subintf_mgr()
virtual subintf_iter_t subintf_iter() const = 0

Returns an iterator for iterating over the subinterfaces in the system. The iterator yields an intf_id_t for each configured subinterface.

virtual bool exists(intf_id_t) const = 0

Returns whether the given subinterface exists.

If exists returns true, then this intf_id_t can be successfully passed into every method of the subintf_mgr. If not, then methods of the subintf_mgr can throw a no_such_interface_error exception.

The exists method of all *intf_mgr classes that manage a given interface (ie intf_mgr, eth_intf_mgr, and subintf_mgr for subinterfaces) are all guaranteed to return the same result.

virtual void subintf_is(intf_id_t) = 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, vlan_id_t) = 0

Creates a subinterface and sets its VLAN tag. If the subinterface already exists, its VLAN tag will be updated.

virtual subintf_t subintf(intf_id_t) const = 0

Returns the subinterface with the given ID. Will return an empty subintf_t if the subinterface does not exist.

virtual void subintf_del(intf_id_t) = 0

Deletes a subinterface. It will simply return if the given subinterface does not exist.

virtual vlan_id_t vlan_tag(intf_id_t) const = 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 void vlan_tag_is(intf_id_t, vlan_id_t) = 0

Configures the VLAN tag of a given subinterface. Throws invalid_argument_error exception if the subinterface does not exist.

virtual intf_id_t parent_intf(intf_id_t) const = 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.

Protected Functions

subintf_mgr()

Private Members

subintf_mgr

Type definitions in subintf

namespace eos
class subintf_t
#include <subintf.h>

This data structure defines a subinterface.

Public Functions

subintf_t()
subintf_t(intf_id_t intf_id, vlan_id_t vlan_id)
intf_id_t intf_id() const

Getter for ‘intf_id’: the interface ID of this subinterface.

vlan_id_t vlan_id() const

Getter for ‘vlan_id’: the VLAN tag of this subinterface.

void vlan_id_is(vlan_id_t vlan_id)

Setter for ‘vlan_id’.

bool operator==(subintf_t const & other) const
bool operator!=(subintf_t const & other) const
uint32_t hash() const

The hash function for type subintf_t.

std::string to_string() const

Returns a string representation of the current object’s values.

Private Members

intf_id_t intf_id_
vlan_id_t vlan_id_

Friends

friend std::ostream & operator<<

A utility stream operator that adds a string representation of subintf_t to the ostream.

Table Of Contents

Previous topic

sdk

Next topic

system