Skip to content

Commit

Permalink
EOS SDK v2.22.1 (EOS 4.29.0F)
Browse files Browse the repository at this point in the history
  • Loading branch information
prufer committed Nov 9, 2022
1 parent 99e5afa commit 79d5651
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 13 deletions.
95 changes: 95 additions & 0 deletions EosSdk.i
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,101 @@ typedef uint64_t uint64_be_t;
$1 = PyLong_AsVoidPtr($input);
}

%typemap(in) eos::ByteString (char *cstr, Py_ssize_t len, std::string temp) {
// If the input Python object is a unicode object then we should convert it
// to UTF-8 before turning it into a bytestring
if (PyUnicode_Check($input)) {
// NB(toma): This may need a check for the unicode -> bytes conversion
// although it should never fail
if (
%#if PY_VERSION_HEX>=0x03000000
PyBytes_AsStringAndSize(
%#else
PyString_AsStringAndSize(
%#endif
PyUnicode_AsUTF8String($input),
&cstr,
&len
) == -1
) {
PyErr_SetString(PyExc_ValueError, "Expected a Unicode object");
SWIG_fail;
}
} else {
// Not unicode, we can just convert
if (
%#if PY_VERSION_HEX>=0x03000000
PyBytes_AsStringAndSize(
%#else
PyString_AsStringAndSize(
%#endif
$input,
&cstr,
&len
) == -1
) {
PyErr_SetString(PyExc_ValueError, "Expected a Bytes object");
SWIG_fail;
}
}
$1 = std::string(cstr);
}

%typemap(in) eos::ByteString& (char *cstr, Py_ssize_t len, std::string temp, int res) {
// If the input Python object is a unicode object then we should convert it
// to UTF-8 before turning it into a bytestring
res = 0;
if (PyUnicode_Check($input)) {
// NB(toma): This may need a check for the unicode -> bytes conversion
// although it should never fail
if (
%#if PY_VERSION_HEX>=0x03000000
PyBytes_AsStringAndSize(
%#else
PyString_AsStringAndSize(
%#endif
PyUnicode_AsUTF8String($input),
&cstr,
&len
) == -1
) {
PyErr_SetString(PyExc_ValueError, "Expected a Unicode object");
SWIG_fail;
}
} else {
// Not unicode, we can just convert
if (
%#if PY_VERSION_HEX>=0x03000000
PyBytes_AsStringAndSize(
%#else
PyString_AsStringAndSize(
%#endif
$input,
&cstr,
&len
) == -1
) {
PyErr_SetString(PyExc_ValueError, "Expected a Bytes value");
SWIG_fail;
}
}
temp = std::string(cstr);
$1 = &temp;
}

%typemap(typecheck) eos::ByteString, eos::ByteString& {
$1 = (PyString_Check($input) || PyUnicode_Check($input)) ? 1 : 0;
}

%typemap(out) eos::ByteString {
// This should only return bytes
%#if PY_VERSION_HEX>=0x03000000
$result = PyBytes_FromStringAndSize($1.c_str(), %numeric_cast($1.size(), Py_ssize_t));
%#else
$result = PyString_FromStringAndSize($1.c_str(), %numeric_cast($1.size(), Py_ssize_t));
%#endif
}

// To make sure instance of EosSdk types are hashable in python, this is important
// when the objects are used in sets, dicts, etc (as key).
// Three test cases added for this, one is in EthLagIntfTest.py, one in IntfTest.py
Expand Down
6 changes: 4 additions & 2 deletions eos/eapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ class EOS_SDK_PUBLIC eapi_mgr {

/// Executes a "show" CLI command in enable mode.
virtual eapi_response_t run_show_cmd(std::string const &) const = 0;
/// As above, but request "text" formatted output (instead of json)
virtual eapi_response_t run_show_cmd_text(std::string const &) const = 0;

/// Executes one or many CLI commands in configuration mode.
virtual eapi_response_t run_config_cmds(
std::vector<std::string> const &) const = 0;

/// like "run_show_cmd" but returns "text" formatted output (instead of json)
virtual eapi_response_t run_show_cmd_text(std::string const &) const = 0;

protected:
eapi_mgr() EOS_SDK_PRIVATE;
private:
Expand Down
5 changes: 3 additions & 2 deletions eos/ham.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <eos/base.h>
#include <eos/base_mgr.h>
#include <eos/types/ham.h>
#include <eos/utility.h>


/**
Expand Down Expand Up @@ -110,7 +111,7 @@ class EOS_SDK_PUBLIC ham_mgr : public base_mgr<ham_handler> {
* reliable/successful or not.
*/
virtual eos::response_enum_t write( eossdk_ham_t ham, register_t reg,
std::string const & data,
eos::ByteString const & data,
bool reliable = false ) = 0;

/**
Expand All @@ -120,7 +121,7 @@ class EOS_SDK_PUBLIC ham_mgr : public base_mgr<ham_handler> {
* 'reliable' represents if the data transfer was reliable/successful or not.
*/
virtual eos::response_enum_t writeBlock( eossdk_ham_t ham, register_t reg,
std::string const & data,
eos::ByteString const & data,
bool reliable = false ) = 0;

protected:
Expand Down
1 change: 1 addition & 0 deletions eos/hash_mix.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef EOS_SDK_HASH_MIX
#define EOS_SDK_HASH_MIX

#include <string>
#include <eos/base.h>

namespace eos {
Expand Down
2 changes: 2 additions & 0 deletions eos/inline/hash_mix.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#ifndef INLINE_HASH_MIX_H
#define INLINE_HASH_MIX_H

#include <string>

namespace eos {

inline hash_mix::hash_mix() : val_(0) {}
Expand Down
2 changes: 2 additions & 0 deletions eos/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace eos {

typedef std::string ByteString;

/**
* Overwriting "<<" operator for uint8_t. The default behavior is to
* print the value out as "char" (sometimes even invisible). What we
Expand Down
51 changes: 46 additions & 5 deletions eos/xcvr.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ class EOS_SDK_PUBLIC xcvr_mgr {
*/
virtual void tx_disabled_is( intf_id_t intf_id, bool disable ) = 0;

/**
* Configures the transmit laser output power.
*/
virtual void tx_output_power_is( intf_id_t intf_id, float power ) = 0;

/**
* Returns the currently active receive laser fine frequency. The frequency
* is in GHz.
Expand All @@ -88,10 +83,56 @@ class EOS_SDK_PUBLIC xcvr_mgr {
*/
virtual bool tx_disabled( intf_id_t intf_id ) const = 0;

/**
* Configures the transmit laser output power.
*/
virtual void tx_output_power_is( intf_id_t intf_id, float power ) = 0;

/**
* Returns the transmit laser power.
*/
virtual float tx_output_power( intf_id_t intf_id ) const = 0;

/**
* Get the turn up state of a coherent transmit laser. Note that currently,
* only CFP2 transceivers are supported.
* Parameters:
* intf_id: The name of an Ethernet interface associated with the
* Returns: The value of the turnUp state as of the last polling interval. If
* the transceiver is not a supported type, or the transceiver is not a
* coherent optic, returns -1.
*/
virtual int32_t tx_turnup_state( intf_id_t intf_id ) const = 0;

/**
* Get the turn up state of a coherent transmit laser. Note that currently,
* only CFP2 transceivers are supported.
* Parameters:
* intf_id: The name of an Ethernet interface associated with the
* Returns: The value of the turnUp state as of the last polling interval. If
* the transceiver is not a supported type, or the transceiver is not a
* coherent optic, returns -1.
*/
virtual int32_t rx_turnup_state( intf_id_t intf_id ) const = 0;

/**
* Returns the data in the register/EEPROM address space of the transceiver.
* Note that currently, only CFP2 transceivers are supported.
* Parameters:
* intf_id: The name of an Ethernet interface associated with the
* transceiver.
* addr: Specifies the address of the register if the transceiver has
* a flat address space (such as CFP2). Specifies the offset of
* the register if the transceiver has a paged address space.
* location: Specifies the technology specific page/bank of the register if
* the transceiver has a paged address space. Not used if the
* transceiver has a flat address space.
* Returns: The value of the register as of the last polling interval. If the
* transceiver is not a supported type, or the register requested is not
* available, returns -1.
*/
virtual int32_t register_read( intf_id_t intf_id, uint16_t addr,
std::string location = "" ) const = 0;
protected:
xcvr_mgr() EOS_SDK_PRIVATE;

Expand Down
4 changes: 2 additions & 2 deletions examples/NexthopGroupModifierScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ int main(int argc, char** argv) {
int size = 8;
int labelstart = 1000000;
std::string name;
std::string nh[4] = {
constexpr size_t nhlen = 4;
std::string nh[nhlen] = {
"2000:10:13::1",
"2000:10:13::3",
"2000:10:13::5",
"2000:10:13::7",
};
size_t nhlen = sizeof(nh)/sizeof(0);
std::string v6start = "2500::";

char v6pfx[128];
Expand Down
13 changes: 11 additions & 2 deletions examples/XcvrMgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class XcvrAgent( eossdk.AgentHandler ):
def __init__( self, agentMgr, xcvrMgr, interfaceNames,
rxFreq, rxFineFreq, txFreq, txDisabled, txOutputPower ):
rxFreq, rxFineFreq, txFreq, txDisabled, txOutputPower, addr ):
self.agentMgr_ = agentMgr
self.xcvrMgr_ = xcvrMgr
self.intfs_ = interfaceNames
Expand All @@ -20,6 +20,7 @@ def __init__( self, agentMgr, xcvrMgr, interfaceNames,
self.txFreq = txFreq
self.txDisabled = txDisabled
self.txOutputPower = txOutputPower
self.addr = addr

def on_initialized( self ):
for intf in self.intfs_:
Expand All @@ -43,6 +44,11 @@ def on_initialized( self ):
print( " tx frequency: %d" % self.xcvrMgr_.tx_frequency( intfId ) )
print( " tx disabled: %s" % self.xcvrMgr_.tx_disabled( intfId ) )
print( " tx output power: %s" % self.xcvrMgr_.tx_output_power( intfId ) )
print( " tx turnup: 0x%X" % self.xcvrMgr_.tx_turnup_state( intfId ) )
print( " rx turnup: 0x%X" % self.xcvrMgr_.rx_turnup_state( intfId ) )
if self.addr is not None:
print( " Addr: 0x%X Data: 0x%X" % (
self.addr, self.xcvrMgr_.register_read( intfId, self.addr ) ) )

self.agentMgr_.exit()

Expand All @@ -62,11 +68,14 @@ def main( args ):
default=False, help="Disable transmitter (omit to enable)" )
parser.add_argument( "-p", "--txOutputPower", dest="txOutputPower", type=float,
default=False, help="Set transmitter output power" )
parser.add_argument( "-g", "--getRegister", dest="addr",
type=lambda x: int( x, 0 ),
default=None, help="Get register value at given address" )
parseArgs = parser.parse_args()
sdk = eossdk.Sdk( 'XcvrMgr' )
_ = XcvrAgent( sdk.get_agent_mgr(), sdk.get_xcvr_mgr(), parseArgs.intfs,
parseArgs.rxFreq, parseArgs.rxFineFreq, parseArgs.txFreq,
parseArgs.txDisabled, parseArgs.txOutputPower )
parseArgs.txDisabled, parseArgs.txOutputPower, parseArgs.addr )
sdk.main_loop( [ 'XcvrMgr' ] )

if __name__ == '__main__':
Expand Down
11 changes: 11 additions & 0 deletions xcvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ class xcvr_mgr_impl : public xcvr_mgr {
void tx_output_power_is( intf_id_t intf_id, float power ) {
}

int32_t tx_turnup_state( intf_id_t intf_id ) const {
return 0;
}
int32_t rx_turnup_state( intf_id_t intf_id ) const {
return 0;
}
int32_t register_read( intf_id_t intf_id, uint16_t addr,
std::string location = "" ) const {
return 0;
}

float rx_fine_frequency( intf_id_t intf_id ) const {
return 0.0;
}
Expand Down

0 comments on commit 79d5651

Please sign in to comment.