-
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.
- Loading branch information
Peter Rufer
committed
Aug 20, 2022
1 parent
d7cb9c8
commit 99e5afa
Showing
24 changed files
with
2,830 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/usr/bin/env pychooser | ||
# Copyright (c) 2015 Arista Networks, Inc. All rights reserved. | ||
# Arista Networks, Inc. Confidential and Proprietary. | ||
|
||
"""A sample custom CLI. | ||
To create a custom CLI, user will need to define their CLI plugin as following: | ||
@EosSdkCli.CustomCli(myCliName) | ||
def Plugin(sdk): | ||
global mySdk, ipRouteMgr | ||
mySdk = sdk | ||
ipRouteMgr = mySdk.get_ip_route_mgr() | ||
Note a manager, such as ipRouteMgr, needs to be obtained in this function and then | ||
used by the CLI implementation, as shown in 'class ShowDynamicIpRoutesCmd'. | ||
User can pass in a name to sdk binding in this CLI plugin via the decorator argument. | ||
After creating the CLI file, such as CustomIpRouteCli.py, it needs to be installed at | ||
/usr/lib/python2.7/site-packages/CliPlugin/ on switch, then user will need to issue | ||
"killall FastCli" to reload all CLIs so the new CLI will take effect. | ||
""" | ||
|
||
from __future__ import absolute_import, division, print_function | ||
import BasicCli | ||
import CliMatcher | ||
import eossdk | ||
import EosSdkCli | ||
import ShowCommand | ||
|
||
ipRouteMgr = None | ||
mySdk = None | ||
|
||
|
||
class ShowDynamicIpRoutesCmd(ShowCommand.ShowCliCommandClass): | ||
syntax = """show dynamic-ip-routes [ tag TAG_NUM ]""" | ||
data = { | ||
'dynamic-ip-routes': 'Routes programmed by EOS SDK agents', | ||
'tag': 'Show only routes with this tag', | ||
'TAG_NUM': CliMatcher.IntegerMatcher( | ||
0, 100, | ||
helpdesc='The dynamic tag for which the routes will be shown'), | ||
} | ||
|
||
def handler(self, mode, args): | ||
tag = args.get('TAG_NUM', 0) | ||
numRoutes = 0 | ||
totalRoutes = 0 | ||
lock = eossdk.SdkScopedLock() | ||
routeFmt = "{} [preference {}, tag {}] has nexthops:" | ||
for route in ipRouteMgr.ip_route_iter(): | ||
totalRoutes += 1 | ||
if not tag or route.tag == tag: | ||
numRoutes += 1 | ||
# Print the route line | ||
print(routeFmt.format(route.key().prefix().to_string(), | ||
route.key().preference(), route.tag())) | ||
|
||
# And now print all the vias for this route | ||
seen_vias = False | ||
for via in ipRouteMgr.ip_route_via_iter(route.key()): | ||
seen_vias = True | ||
# Only print out the relevant via information | ||
if via.hop() != eossdk.IpAddr(): | ||
output = "Nexthop " + via.hop().to_string() | ||
elif via.intf() != eossdk.IntfId(): | ||
if via.intf().is_null0(): | ||
output = "Drop route" | ||
else: | ||
output = "Interface " + via.intf.to_string | ||
elif via.nexthop_group(): | ||
output = "Nexthop group " + via.nexthop_group() | ||
else: | ||
output = "Unknown via type" | ||
|
||
if via.mpls_label() != eossdk.MplsLabel(): | ||
output = " and push MPLS Label " + via.mpls_label().to_string() | ||
print(" -", output) | ||
|
||
if not seen_vias: | ||
print(" - no nexthops!") | ||
|
||
del lock | ||
|
||
# Print a nice footer | ||
print() | ||
print("Saw", numRoutes, "matching routes out of", totalRoutes, "total routes") | ||
print() | ||
|
||
BasicCli.addShowCommandClass( ShowDynamicIpRoutesCmd ) | ||
|
||
|
||
@EosSdkCli.CustomCli("MyCustomIpRouteCli") | ||
def Plugin(sdk): | ||
global mySdk, ipRouteMgr | ||
mySdk = sdk | ||
ipRouteMgr = mySdk.get_ip_route_mgr() |
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,73 @@ | ||
#!/usr/bin/env pychooser | ||
# Copyright (c) 2015 Arista Networks, Inc. All rights reserved. | ||
# Arista Networks, Inc. Confidential and Proprietary. | ||
|
||
"""A sample custom CLI to change the default vlan of an interface in access mode. | ||
To create a custom CLI, user will need to define their CLI plugin as following: | ||
@EosSdkCli.CustomCli(myCliName) | ||
def Plugin(sdk): | ||
global mySdk, ethIntfMgr | ||
mySdk = sdk | ||
ethIntfMgr = mySdk.get_eth_intf_mgr() | ||
Note a manager, such as ethIntfMgr, needs to be obtained in this function and then | ||
used by the CLI implementation, as shown in 'class MoveAccessInterfaceCmd'. | ||
User can pass in a name to sdk binding in this CLI plugin via the decorator argument. | ||
After creating the CLI file, such as CustomMoveAccessInterfaceCli.py, it needs to be | ||
installed at /usr/lib/python2.7/site-packages/CliPlugin/ on switch, then user will | ||
need to issue "killall FastCli" to reload all CLIs so the new CLI will take effect. | ||
""" | ||
|
||
from __future__ import absolute_import, division, print_function | ||
import BasicCli | ||
import CliMatcher | ||
import CliCommand | ||
import eossdk | ||
import EosSdkCli | ||
|
||
ethIntfMgr = None | ||
mySdk = None | ||
|
||
|
||
class MoveAccessInterfaceCmd(CliCommand.CliCommandClass): | ||
syntax = 'move access interfaces SRC_VLAN DST_VLAN' | ||
data = { | ||
'move': 'Move command', | ||
'access': 'Access interface', | ||
'interfaces': 'Interface', | ||
'SRC_VLAN': CliMatcher.IntegerMatcher( | ||
1, 4094, | ||
helpdesc='The original default VLAN ID to be moved'), | ||
'DST_VLAN': CliMatcher.IntegerMatcher( | ||
1, 4094, | ||
helpdesc='The new default VLAN ID to be moved to'), | ||
} | ||
|
||
@staticmethod | ||
def handler(mode, args): | ||
original_vlan_id = args['SRC_VLAN'] | ||
new_vlan_id = args['DST_VLAN'] | ||
lock = eossdk.SdkScopedLock() | ||
for intf in ethIntfMgr.eth_intf_iter(): | ||
if (ethIntfMgr.switchport_mode(intf) == eossdk.SWITCHPORT_MODE_ACCESS and | ||
ethIntfMgr.default_vlan(intf) == original_vlan_id): | ||
ethIntfMgr.default_vlan_is(intf, new_vlan_id) | ||
print("moved interface %s default VLAN from %s to %s." % | ||
(intf.to_string(), original_vlan_id, new_vlan_id)) | ||
return | ||
print("no default VLAN ID moved.") | ||
print() | ||
del lock | ||
|
||
BasicCli.GlobalConfigMode.addCommandClass( MoveAccessInterfaceCmd ) | ||
|
||
|
||
@EosSdkCli.CustomCli("MyCustomMoveAccessInterfaceCli") | ||
def Plugin(sdk): | ||
global mySdk, ethIntfMgr | ||
mySdk = sdk | ||
ethIntfMgr = mySdk.get_eth_intf_mgr() |
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,94 @@ | ||
// Copyright (c) 2021 Arista Networks, Inc. All rights reserved. | ||
// Arista Networks, Inc. Confidential and Proprietary. | ||
|
||
#include <eos/agent.h> | ||
#include <eos/sdk.h> | ||
#include <eos/tracing.h> | ||
#include <eos/ham.h> | ||
#include <eos/types/ham.h> | ||
#include <assert.h> | ||
#include <unistd.h> | ||
#include <string> | ||
|
||
class ham_agent : public eos::agent_handler { | ||
|
||
public: | ||
eos::tracer t; | ||
eos::ham_mgr *ham_mgr_; | ||
|
||
explicit ham_agent(eos::sdk & sdk) | ||
: eos::agent_handler(sdk.get_agent_mgr()), | ||
t("HamAgent"), | ||
ham_mgr_(sdk.get_ham_mgr()){ | ||
t.trace0("Agent constructed"); | ||
} | ||
|
||
void on_initialized(){ | ||
t.enabled_is(eos::Level0, true); | ||
t.trace0("Initialized"); | ||
get_agent_mgr()->status_set("Ready_for_testing", "True"); | ||
t.trace0("Set the status to ready for testing"); | ||
} | ||
|
||
void on_agent_option(std::string const & option_name, | ||
std::string const & value ){ | ||
// Create ham using createFromAddress funciton call | ||
// Create aham_address_t to pass in | ||
auto aham_address = eos::aham_address_t(); | ||
// Initialize aham_address to be passed to HAM constructor | ||
// Initialize bus ID to 0 and address to 0x48 because those are | ||
// the corresponding values for the temperature sensor we will be | ||
// writing to/reading from | ||
aham_address.bus_is( 1 ); | ||
aham_address.accelerator_is( 0 ); | ||
aham_address.address_is( 0x48 ); | ||
// Initialize pci_address to be passed to HAM constructor | ||
// Initialize all fields to 0 because we are testing on | ||
// dropbear duts, which have all fields for pci addr as 0 | ||
auto pci_address = eos::pci_address_t(); | ||
pci_address.domain_is( 0 ); | ||
pci_address.bus_is( 0 ); | ||
pci_address.device_is( 0 ); | ||
pci_address.function_is( 0 ); | ||
auto eossdk_ham_from_address = eos::eossdk_ham_t( aham_address, pci_address ); | ||
if(option_name == "test_write_and_read_8"){ | ||
// Hardcode address at 0x03, which represents the address of the | ||
// overtemperature sensor on a lm75 temperature sensor on a 7130, | ||
// to write to/read from in the test | ||
auto reg = eos::register_t() ; | ||
reg.reg_is(0x03); | ||
// Convert value to appropriate type to pass to write8 | ||
uint8_t val = stoi(value); | ||
ham_mgr_->write8(eossdk_ham_from_address,reg, val, true); | ||
auto retVal = ham_mgr_->read8(eossdk_ham_from_address, reg); | ||
uint8_t valueRead = retVal.result(); | ||
t.trace0("Value read was: %d", valueRead); | ||
assert(retVal.status() == eos::STATUS_OK); | ||
assert (valueRead == val); | ||
get_agent_mgr()->status_set("test_write_and_read_8", | ||
"Value successfully written and read."); | ||
} | ||
else if(option_name == "test_write_and_read_16"){ | ||
// Hardcode address to write to/read from into test | ||
auto reg = eos::register_t() ; | ||
reg.reg_is(0x03); | ||
// Convert value to appropriate type to pass to write16 | ||
uint16_t val = stoi(value); | ||
ham_mgr_->write16(eossdk_ham_from_address, reg, val, true); | ||
auto retVal = ham_mgr_->read16(eossdk_ham_from_address, reg); | ||
uint16_t valueRead = retVal.result(); | ||
t.trace0( "Value read was: %d", valueRead ); | ||
assert(valueRead == val); | ||
assert(retVal.status() == eos::STATUS_OK); | ||
get_agent_mgr()->status_set("test_write_and_read_16", | ||
"Value successfully written and read."); | ||
} | ||
} | ||
|
||
}; | ||
|
||
int main(int argc, char ** argv){ | ||
eos::sdk sdk; | ||
ham_agent agent(sdk); | ||
sdk.main_loop(argc, argv); | ||
} |
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,50 @@ | ||
// Copyright (c) 2014 Arista Networks, Inc. All rights reserved. | ||
// Arista Networks, Inc. Confidential and Proprietary. | ||
|
||
#include <eos/agent.h> | ||
#include <eos/intf.h> | ||
#include <eos/ip_intf.h> | ||
#include <eos/sdk.h> | ||
#include <eos/tracing.h> | ||
|
||
/** | ||
* This example agent program displays changes to the | ||
* internal VLAN ID mappings via tracing. Compile it | ||
* and copy it to a switch and run it, e.g.,; | ||
* | ||
* $ scp InternalVlan switch:/mnt/flash/ | ||
* $ ssh switch | ||
* switch# bash | ||
* Arista Networks EOS shell | ||
* | ||
* $ TRACE="InternalVlanId*" /mnt/flash/InternalVlan | ||
*/ | ||
|
||
class internal_vlan_id : public eos::agent_handler, | ||
public eos::ip_intf_handler { | ||
public: | ||
eos::tracer t; | ||
|
||
explicit internal_vlan_id(eos::sdk & sdk) | ||
: eos::agent_handler(sdk.get_agent_mgr()), | ||
eos::ip_intf_handler(sdk.get_ip_intf_mgr()), | ||
t("InternalVlanId") { | ||
t.trace0("Agent constructed"); | ||
watch_all_ip_intfs(true); | ||
} | ||
|
||
void on_initialized() { | ||
t.trace0("Initialized"); | ||
} | ||
|
||
void on_internal_vlan_id(eos::intf_id_t const & i, eos::vlan_id_t vlan_id) { | ||
t.trace0("on_internal_vlan_id: intf %s vlan_id %d", | ||
i.to_string().c_str(), vlan_id); | ||
} | ||
}; | ||
|
||
int main(int argc, char ** argv) { | ||
eos::sdk sdk; | ||
internal_vlan_id agent(sdk); | ||
sdk.main_loop(argc, argv); | ||
} |
Oops, something went wrong.