4. Modules¶
4.1. Endpoint¶
An endpoint is an OMCI client or server.
Endpoints are modeled by instances of the Endpoint class. Examples:
client = Endpoint((address, port), is_server=False, cterm_name='foo',
onu_id_range=range(100))
message = ...
client.send(message)
response, address = client.recv()
client.process(response)
server = Endpoint((address, port), is_server=True, cterm_name='foo',
onu_id_range=range(100))
message, address = server.recv()
response = server.process(message)
if response:
server.send(response, address)
-
class
obbaa_onusim.endpoint.Endpoint(server_address, *, is_server=True, cterm_name=None, onu_id_range=None, tr451=True, timeout=10, dumpfd=None)¶ Bases:
objectModels an OMCI client or server instance.
Note
There should probably be an
Endpointbase class withClientandServersubclasses.-
__init__(server_address, *, is_server=True, cterm_name=None, onu_id_range=None, tr451=True, timeout=10, dumpfd=None)¶ Create an OMCI endpoint instance.
- Parameters
server_address (
Tuple[str,int]) – Server address (and port). Clients send to this address; servers listen on it.is_server (
bool) – Whether or not this endpoint is a server.cterm_name (
Optional[str]) – Channel termination name. Clients include this name in all messages. Servers will process only messages that contain it.onu_id_range (
Optional[range]) – ONU id range, e.g.range(10)means ONU ids 0, 1, …9. Ignored by clients. Servers will process only messages that contain one of these ONU ids.tr451 (
bool) – Whether to process TR-451 (cterm_name,onu_id) headers.timeout (
int) – Clients will time out after this number of seconds. Ignored by servers.dumpfd (
Optional[IO[str]]) – File to which to send hex dumps of all sent and received messages (ignoring the TR-451 header).
-
recv(*, bufsize=2048)¶ Receive a buffer from the server socket and decode it as a message.
- Parameters
bufsize (
int) – Buffer size in bytes.- Return type
Tuple[Message,Tuple[str,int]]- Returns
Decoded message and the address from which it was received.
-
process(message)¶ Process a received message.
- Parameters
message (
Message) – Message to process.- Return type
Optional[Message]- Returns
None (if no response is requested) or the response.
Note
Messages that don’t have an expected
cterm_nameoronu_idwill be ignored and no response will be sent. This is probably wrong.
-
send(message, address=None)¶ Send a message to the server or the specified address.
- Parameters
message (
Message) – Message to send.address (
Optional[Tuple[str,int]]) – Address to send the message to. Defaults to the server address.
- Return type
None
-
property
server_address¶ Server address.
- Return type
Tuple[str,int]
-
__str__()¶ Return str(self).
-
4.2. Messages and Actions¶
Message classes¶
OMCI messages are modeled by subclasses of the Message base class.
Message instances can be created in two ways:
Directly via
Message.__init__: this is how clients create requests and servers create responses and notificationsBy calling
Message.decodeto decode a received message: this is how servers decode requests and clients decode responses and notifications
Examples:
values = {'battery_backup': True}
message = Set(cterm_name='foo', onu_id=42, tci=42, extended=False,
me_class=256, me_inst=0, values=values)
# common fields can be put in a dictionary and used like this
common = {'cterm_name': 'foo', 'onu_id': 42, 'tci': 42, 'extended': False}
message = Set(me_class=256, me_inst=0, values=values, **common)
buffer, address = sock.recvfrom(bufsize)
message = Message.decode(buffer)
# the __str__() method returns a user-friendly string representation
print(message)
-
class
obbaa_onusim.message.Message(_no_validate=False, **fields)¶ Bases:
objectMessagebase class.The methods are documented in a logical order corresponding to a message’s life-cycle:
__init__constructs the message from its field valuesencodeconverts the message to an OMCI buffer(the buffer is now presumably sent over the network)
decodeconverts an OMCI buffer back to a messageprocessprocesses the message, maybe constructing a response message
-
__init__(_no_validate=False, **fields)¶ Messagebase class constructor.Subclasses will not usually need to provide their own constructors because they can supply their own fields via the base class constructor.
- Parameters
_no_validate (
bool) – This is for internal use only.**fields –
Keyword arguments. There are several categories of field:
The TR-451 header fields (
cterm_name,onu_id=42) must always be suppliedThe OMCI message type fields (
type_ar,type_ak,type_mt) are handled automatically and so must not be suppliedThese OMCI header fields have defaults but can be overridden:
tci(Transaction Correlation Identifier); 0-65535; default 0extended(whether to use extended messages); default False
These OMCI header fields do not have defaults and therefore must be supplied:
me_class(Managed Entity Class); 0-65535me_inst(Managed Entity Instance); 0-65535
Any additional fields are message type specific
-
validate()¶ Validate a message, returning a dictionary of modified fields.
This is primarily intended for when an application calls the constructor directly and therefore have supplied some invalid fields.
If this method detects an unrecoverable error, it should raise an exception.
The base class implementation just returns an empty dictionary. Subclasses should override this method.
- Return type
Dict[str,Union[bytes,int,str,dict,list]]- Returns
Dictionary mapping field names to field values. The instance will be updated with these fields.
-
encode(*, tr451=True)¶ Encode this message into a buffer.
- Parameters
tr451 (
bool) – Whether to add a TR-451 header to the buffer.- Return type
bytearray- Returns
The encoded buffer.
-
encode_contents()¶ Encode this message’s contents, i.e. its type-specific payload.
The base class implementation just returns an empty buffer. Subclasses should override this method.
- Return type
bytearray- Returns
Encoded buffer.
-
classmethod
decode(buffer, *, tr451=True)¶ Decode a buffer, returning a
Messageinstance of the appropriate type.
-
decode_contents(contents)¶ Decode this message’s contents, i.e. its type-specific payload.
- Parameters
contents (
bytearray) – The contents part of the buffer.- Return type
Dict[str,Union[bytes,int,str,dict,list]]- Returns
Dictionary mapping field names to field values. The instance will be updated with these fields.
-
process(endpoint)¶ Pass this message to the endpoint for processing, and return the response (if any).
- Parameters
endpoint (
object) – Endpoint to which to pass the message for processing.- Return type
Optional[Message]- Returns
The response, or
Noneif there is no response.
-
get(name, default=None)¶ Get the value of the named field.
- Parameters
name (
str) – Field name.default (
Union[bytes,int,str,dict,list,None]) – Value to return if the field doesn’t exist.
- Return type
Union[bytes,int,str,dict,list]- Returns
Field value.
Note
It will usually be more convenient to rely on the fact that
__getattr__has been defined to return field values directly. Assuming that fieldfooexists, these are the same:self.get('foo') self.foo
As with dictionaries, if you’re not sure whether the field exists, it’s safer to use
get().
-
set(name, value)¶ Set the value of the named field.
- Parameters
name (
str) – Field name.value (
Union[bytes,int,str,dict,list]) – Field value.
Note
The field name isn’t checked, so it’s possible to inadvertently create new fields using this method.
- Return type
None
-
__str__()¶ Return a user-friendly representation of a message.
Example:
values = {'battery_backup': True} message = Set(cterm_name='foo', onu_id=42, tci=84, me_class=256, me_inst=0, values=values) print(message) -> Set(attr_mask=0x400, cterm_name='foo', extended=False, me_class=256, me_inst=0, onu_id=42, tci=84, values={'battery_backup': 1})
Note
Oops. This example shows that value conversion between user and raw units isn’t yet complete.
- Return type
str
Action classes¶
An action is an operation, typically involving a command/response message round-trip.
-
class
obbaa_onusim.action.Action(number, name, description=None, request=None, response=None)¶ Bases:
obbaa_onusim.types.NumberName,obbaa_onusim.types.AutoGetterActionclass.-
__init__(number, name, description=None, request=None, response=None)¶ Actionconstructor.- Parameters
number (
int) – Action number. This is the OMCI message type (type_mt) for the action’s request and response messages.name (
str) – Action name. This is only used for documentation purposes.description (
Optional[str]) – Action description. This is only used for documentation purposes.request (
Optional[Type[Message]]) – Request message class.response (
Optional[Type[Message]]) – Response message class. IfNoneno response is expected.
-
-
class
obbaa_onusim.action.Arg(number, name, description=None, data=None, cond=None)¶ Bases:
obbaa_onusim.types.NumberName,obbaa_onusim.types.AutoGetter-
__init__(number, name, description=None, data=None, cond=None)¶ Initialize self. See help(type(self)) for accurate signature.
-
Set action¶
The Set action’s messages are defined in G.988 A.2.5-6 (extended) and A.3.5-6 (baseline).
The relevant classes and instances are:
Set: Set command message classSetResponse: Set response message classset_action: Set action instance
-
class
obbaa_onusim.actions.set.Set(_no_validate=False, **fields)¶ Bases:
obbaa_onusim.message.MessageSet command message.
-
validate()¶ Validate the
valuesfield (a dictionary), returning new values for theattr_maskandvaluesfields.For each item in the
valuesdictionary:Check it’s a valid attribute name or number
Check it’s a writable attribute
If any of the checks fail, output a warning and ignore the attribute.
- Return type
Dict[str,Union[bytes,int,str,dict,list]]- Returns
- Dictionary with the following items.
attr_mask: attribute mask containing bits for valid attributes from the supplied valuesvalues: dictionary containing valid attributes from the supplied values, and with raw attribute values
-
encode_contents()¶ Encode this message’s contents, i.e. its type-specific payload.
The base class implementation just returns an empty buffer. Subclasses should override this method.
- Return type
bytearray- Returns
Encoded buffer.
-
decode_contents(contents)¶ Decode this message’s contents, i.e. its type-specific payload.
- Return type
Dict[str,Union[bytes,int,str,dict,list]]- Returns
Dictionary with the following items.
attr_mask: attribute mask; 0-65535values: MIB-specific attribute names and values as specified by the attribute mask
Note
SetandGetResponseare inconsistent: here the dictionary contains avaluesitem, butGetResponseplaces the attributes directly in the object. This inconsistency will be resolved.
-
process(server)¶ Pass this message to the endpoint for processing, and return the response (if any).
- Parameters
endpoint – Endpoint to which to pass the message for processing.
- Return type
- Returns
The response, or
Noneif there is no response.
-
-
class
obbaa_onusim.actions.set.SetResponse(_no_validate=False, **fields)¶ Bases:
obbaa_onusim.message.MessageSet response message.
-
encode_contents()¶ Encode this message’s contents, i.e. its type-specific payload.
The base class implementation just returns an empty buffer. Subclasses should override this method.
- Return type
bytearray- Returns
Encoded buffer.
-
decode_contents(contents)¶ Decode this message’s contents, i.e. its type-specific payload.
- Return type
Dict[str,Union[bytes,int,str,dict,list]]- Returns
Dictionary with the following items.
reason: result, reason; 0-255attr_mask: attribute mask; 0-65535If
reasonis0b1001(9): *opt_attr_mask: optional-attribute mask; 0-65535 *opt_exec_mask: attribute execution mask; 0-65535
-
Get action¶
The Get action’s messages are defined in G.988 A.2.7-8 (extended) and A.3.7-8 (baseline).
The relevant classes and instances are:
Get: Get command message classGetResponse: Get response message classget_action: Get action instance.
-
class
obbaa_onusim.actions.get.Get(_no_validate=False, **fields)¶ Bases:
obbaa_onusim.message.MessageGet command message.
-
encode_contents()¶ Encode this message’s contents, i.e. its type-specific payload.
The base class implementation just returns an empty buffer. Subclasses should override this method.
- Return type
bytearray- Returns
Encoded buffer.
-
decode_contents(contents)¶ Decode this message’s contents, i.e. its type-specific payload.
- Return type
Dict[str,Union[bytes,int,str,dict,list]]- Returns
Dictionary with the following items.
attr_mask: attribute mask; 0-65535
-
process(server)¶ Pass this message to the endpoint for processing, and return the response (if any).
- Parameters
endpoint – Endpoint to which to pass the message for processing.
- Return type
- Returns
The response, or
Noneif there is no response.
-
-
class
obbaa_onusim.actions.get.GetResponse(_no_validate=False, **fields)¶ Bases:
obbaa_onusim.message.MessageGet response message.
-
encode_contents()¶ Encode this message’s contents, i.e. its type-specific payload.
The base class implementation just returns an empty buffer. Subclasses should override this method.
- Return type
bytearray- Returns
Encoded buffer.
-
decode_contents(contents)¶ Decode this message’s contents, i.e. its type-specific payload.
- Return type
Dict[str,Union[bytes,int,str,dict,list]]- Returns
Dictionary with the following items.
reason: result, reason; 0-255attr_mask: attribute mask; 0-65535opt_attr_mask: optional-attribute mask; 0-65535opt_exec_mask: attribute execution mask; 0-65535other: MIB-specific attributes as specified by the attribute mask
-
MIB upload and MIB upload next actions¶
The MIB upload and MIB upload next actions’ messages are defined in G.988 A.2.13-16 (extended) and A.3.13-16 (baseline).
The relevant classes and instances are:
MibUploadandMibUploadNext: MIB upload and MIB upload next command message classesMibUploadResponseandMibUploadNextResponse: MIB upload and MIB upload next response message classesmib_upload_actionandmib_upload_next_action: MIB upload and MIB upload next action instances.
-
class
obbaa_onusim.actions.upload.MibUpload(_no_validate=False, **fields)¶ Bases:
obbaa_onusim.message.MessageMIB upload command message.
-
process(server)¶ Pass this message to the endpoint for processing, and return the response (if any).
- Parameters
endpoint – Endpoint to which to pass the message for processing.
- Return type
- Returns
The response, or
Noneif there is no response.
-
-
class
obbaa_onusim.actions.upload.MibUploadResponse(_no_validate=False, **fields)¶ Bases:
obbaa_onusim.message.MessageMIB upload response message.
-
encode_contents()¶ Encode this message’s contents, i.e. its type-specific payload.
The base class implementation just returns an empty buffer. Subclasses should override this method.
- Return type
bytearray- Returns
Encoded buffer.
-
decode_contents(contents)¶ Decode this message’s contents, i.e. its type-specific payload.
- Return type
Dict[str,Union[bytes,int,str,dict,list]]- Returns
Dictionary with the following items.
num_upload_nexts: number ofMibUploadNextcommands required; 0-65535
-
-
class
obbaa_onusim.actions.upload.MibUploadNext(_no_validate=False, **fields)¶ Bases:
obbaa_onusim.message.MessageMIB upload next command message.
-
encode_contents()¶ Encode this message’s contents, i.e. its type-specific payload.
The base class implementation just returns an empty buffer. Subclasses should override this method.
- Return type
bytearray- Returns
Encoded buffer.
-
decode_contents(contents)¶ Decode this message’s contents, i.e. its type-specific payload.
- Return type
Dict[str,Union[bytes,int,str,dict,list]]- Returns
Dictionary with the following items.
seq_num: command sequence number; 0-65535
-
process(server)¶ Pass this message to the endpoint for processing, and return the response (if any).
- Parameters
endpoint – Endpoint to which to pass the message for processing.
- Return type
- Returns
The response, or
Noneif there is no response.
-
-
class
obbaa_onusim.actions.upload.MibUploadNextResponse(_no_validate=False, **fields)¶ Bases:
obbaa_onusim.message.MessageMIB upload next response message.
-
encode_contents()¶ Encode this message’s contents, i.e. its type-specific payload.
The base class implementation just returns an empty buffer. Subclasses should override this method.
- Return type
bytearray- Returns
Encoded buffer.
-
decode_contents(contents)¶ Decode this message’s contents, i.e. its type-specific payload.
- Return type
Dict[str,Union[bytes,int,str,dict,list]]- Returns
Dictionary with the following items.
me_class.me_inst.attr_name: the item name is thedot-separated ME class (MIB number), ME instance, and attribute name.
-
MIB reset action¶
The MIB reset action’s messages are defined in G.988 A.2.17-18 ( extended) and A.3.17-18 (baseline).
The relevant classes and instances are:
MibReset: MIB reset command message classMibResetResponse: MIB reset response message classmib_reset_action: MIB reset action instance.
-
class
obbaa_onusim.actions.reset.MibReset(_no_validate=False, **fields)¶ Bases:
obbaa_onusim.message.MessageMIB reset command message.
-
process(server)¶ Pass this message to the server database for processing, and return the response.
- Return type
-
-
class
obbaa_onusim.actions.reset.MibResetResponse(_no_validate=False, **fields)¶ Bases:
obbaa_onusim.message.MessageMIB reset response message.
-
encode_contents()¶ Encode this message’s contents, i.e. its type-specific payload.
The base class implementation just returns an empty buffer. Subclasses should override this method.
- Return type
bytearray- Returns
Encoded buffer.
-
decode_contents(contents)¶ Decode this message’s contents, i.e. its type-specific payload.
- Return type
Dict[str,Union[bytes,int,str,dict,list]]- Returns
Dictionary with the following items.
reason: result, reason; 0-255
-
4.3. MIBs¶
MIB classes¶
A MIB (Management Information Base), also referred to as an ME (Managed
Entity), is defined via a MIB instance.
A MIB definition describes its Attrs (attributes), Actions,
Notifications, Changes and Alarms.
Example:
onu_data_mib = MIB(2, 'ONU_DATA', 'Models the MIB itself', attrs=(
Attr(0, 'me_inst', 'Managed entity instance', R, M, Number(2, fixed=0)),
Attr(1, 'mib_data_sync', 'MIB data sync', RW, M, Number(1))
), actions= (
get_action, set_action, get_all_alarms_action,
get_all_alarms_next_action, mib_reset_action, mib_upload_action,
mib_upload_next_action
))
-
obbaa_onusim.mib.mibs= {mib.number: mib for mib in all-MIB-instances}¶ All instantiated MIBs.
-
class
obbaa_onusim.mib.MIB(number, name, description=None, *, attrs=None, actions=None, notifications=None, changes=None, alarms=None)¶ Bases:
obbaa_onusim.types.NumberName,obbaa_onusim.types.AutoGetterMIB definition class.
-
__init__(number, name, description=None, *, attrs=None, actions=None, notifications=None, changes=None, alarms=None)¶ MIB class constructor.
The constructor adds new MIB instances to the
mibsdictionary.- Parameters
number (
int) – MIB number; MUST be unique across all MIB instances; 0-65535.name (
str) – MIB name; MUST be unique across all MIB instances.description (
Optional[str]) – MIB description; used only for documentation purposes.attrs (
Optional[Tuple[Attr, …]]) – MIB attributes. They’re defined as a tuple but each has a number, so order doesn’t matter.actions (
Optional[Tuple[Action, …]]) – Actions valid for use with this MIB.notifications (
Optional[Tuple[Notification, …]]) – Notifications generated by this MIB.changes (
Optional[Tuple[Change, …]]) – Changes generated by this MIB.alarms (
Optional[Tuple[Alarm, …]]) – Alarms generated by this MIB.
-
attr(number_or_name)¶ Find a MIB attribute by number or name, returning the attribute or None.
-
attr_names(access=None)¶ Return a (string representation of) a list of all attribute names, optionally restricted to those with a specified access level.
- Parameters
access (
Optional[Access]) – Desired access level, orNoneto return all attributes.- Return type
str- Returns
String of the form
name1, name2, name3.
Note
Attribute 0 is
me_inst(the ME instance number) and is not returned.
-
-
class
obbaa_onusim.mib.Attr(number, name, description=None, access=None, requirement=None, data=None)¶ Bases:
obbaa_onusim.types.NumberName,obbaa_onusim.types.AutoGetterMIB attribute class.
-
__init__(number, name, description=None, access=None, requirement=None, data=None)¶ MIB attribute constructor.
- Parameters
number (
int) – attribute number; MUST be unique within its MIB; 0-16.name (
str) – attribute name; MUST be unique within its MIB.description (
Optional[str]) – attribute description; used only for documentation purposes.access (
Optional[Access]) – attribute access level.requirement (
Optional[Requirement]) – attribute support requirementdata (
Union[Datum,Tuple[Datum, …],None]) – attribute data specification.
-
decode(content, offset)¶ Decode a MIB attribute value.
- Parameters
content (
bytearray) – buffer from which to decode the value.offset (
int) – byte offset within buffer at which to start decoding.
- Return type
Tuple[Union[bytearray,int,str,Tuple[Union[bytearray,int,str], …]],int]- Returns
Decoded values and updated offset.
The decoded values are returned as a tuple (if there’s more than one value), a single value, or
NoneThe offset is ready to be passed to the next
decodeinvocation
-
encode(values=None)¶ Encode a MIB attribute value.
- Parameters
values (
Union[bytearray,int,str,Tuple[Union[bytearray,int,str], …],None]) – tuple, single value orNone.- Return type
bytearray- Returns
Encoded buffer. If
Nonewas supplied, an empty buffer is returned.
-
resolve(values=None)¶ Resolve a MIB attribute value by invoking any callable values.
Any callable values are invoked (with no arguments) and are replaced with the returned value. See
Databasefor an example.- Parameters
values (
Union[bytearray,int,str,Tuple[Union[bytearray,int,str], …],None]) – tuple, single value orNone.- Return type
Union[bytearray,int,str,Tuple[Union[bytearray,int,str], …]]- Returns
Resolved values. If
Nonewas supplied, thenNoneis returned.
-
property
mask¶ Get this attribute’s mask, e.g. the value to use when forming the
Getcommand’sattr_maskfield.Note
Don’t call this on attribute 0 (
me_inst). You’ll get an assertion failure.
-
property
size¶ Get this attribute’s value size in bytes.
-
-
class
obbaa_onusim.mib.Access(name)¶ Bases:
obbaa_onusim.types.Name,obbaa_onusim.types.AutoGetterAttribute access class (G.988 Section 9).
-
__init__(name)¶ Initialize self. See help(type(self)) for accurate signature.
-
-
obbaa_onusim.mib.R= Access(name='R')¶ Read-only access.
-
obbaa_onusim.mib.W= Access(name='W')¶ Write-only access.
-
obbaa_onusim.mib.RW= Access(name='RW')¶ Read-Write access.
-
obbaa_onusim.mib.RC= Access(name='RC')¶ Read and set-by-Create access.
-
obbaa_onusim.mib.RWC= Access(name='RWC')¶ Read-Write and set-by-Create access.
-
class
obbaa_onusim.mib.Requirement(name)¶ Bases:
obbaa_onusim.types.Name,obbaa_onusim.types.AutoGetterAttribute requirement class.
-
__init__(name)¶ Initialize self. See help(type(self)) for accurate signature.
-
-
obbaa_onusim.mib.M= Requirement(name='M')¶ Mandatory
-
obbaa_onusim.mib.O= Requirement(name='O')¶ Optional
-
class
obbaa_onusim.mib.Notification(name, description=None, *, names=None)¶ Bases:
obbaa_onusim.types.Name,obbaa_onusim.types.AutoGetterAttribute notification class.
-
obbaa_onusim.mib.test_result_notification= Notification(name='test_result')¶ Test result notification.
-
class
obbaa_onusim.mib.Change(number, name, description=None, *, names=None)¶ Bases:
obbaa_onusim.types.NumberNameAttribute change class.
-
class
obbaa_onusim.mib.Alarm(number, name, description=None, *, names=None)¶ Bases:
obbaa_onusim.types.NumberNameAttribute alarm class.
ONU-G MIB¶
ONU-G MIB (G.988 9.1.1).
ONU2-G MIB¶
ONU2-G MIB (G.988 9.1.2).
ONU data MIB¶
ONU data MIB (G.988 9.1.3).
4.4. Database¶
MIB database access.
This will currently only really work on the server side, but it makes sense
also to have a client-side database, populated via get and
MIB upload actions.
-
obbaa_onusim.database.specs= ((MIB(number=256, name='ONU-G', description='Represents the ONU as equipment'), ({'me_inst': 0, 'vendor_id': 1234, 'version': 'v2', 'serial_number': ('abcdefgh', 5678)},)), (MIB(number=257, name='ONU2-G', description='Contains additional attributes associated with a PON ONU'), ({'me_inst': 0, 'omcc_version': 180, 'sys_up_time': <function <lambda>>},)), (MIB(number=2, name='ONU data', description='Models the MIB itself'), ({'me_inst': 0, 'mib_data_sync': 0},)), (MIB(number=7, name='Software image', description='Models an executable software image'), ({'me_inst': 0}, {'me_inst': 1}, {'me_inst': 256}, {'me_inst': 257})))¶ MIB instance specs (these are instantiated on all ONUs).
Note
These specs should be read from JSON/YAML files.
-
obbaa_onusim.database.mibs= {2: MIB(number=2, name='ONU data', description='Models the MIB itself'), 7: MIB(number=7, name='Software image', description='Models an executable software image'), 256: MIB(number=256, name='ONU-G', description='Represents the ONU as equipment'), 257: MIB(number=257, name='ONU2-G', description='Contains additional attributes associated with a PON ONU')}¶ Implemented MIBs, i.e. the MIBs referenced by the MIB instance specs.
-
class
obbaa_onusim.database.Results¶ Bases:
objectDatabase results class (used for all database operations).
-
__init__()¶ Database results constructor.
-
reason: int¶ Reason, result (used by all operations).
-
attr_mask: int¶ Attribute mask (used by most operations).
-
opt_attr_mask: int¶ Optional-attribute mask (used with reason 0b1001).
-
attr_exec_mask: int¶ Attribute-execution mask (used with reason 0b1001).
-
attrs: List[Tuple[Attr, AttrDataValues]]¶ Attributes and their values (used by
Database.get).
-
num_upload_nexts: int¶ Number of upload-nexts (used by
Database.upload).
-
body: List[int, List[Snapshot]]¶ Next message body (used by
Database.upload_next).
-
__str__()¶ Return str(self).
-
-
class
obbaa_onusim.database.Database(onu_id_range)¶ Bases:
objectMIB database class.
-
__init__(onu_id_range)¶ MIB database constructor.
- Parameters
onu_id_range (
range) – ONU id range, e.g.range(10)means ONU ids 0, 1, …9. An identical database is instantiated for each of these ONU ids.
-
set(onu_id, me_class, me_inst, attr_mask, values, *, extended=False)¶ Set the specified attribute values.
- Parameters
onu_id – ONU id.
me_class – MIB class.
me_inst – MIB instance.
attr_mask – attributes to set.
values – values to which attributes will be set.
extended – whether an extended message has been requested.
- Return type
- Returns
Results object, including
reasonandopt_attr_mask.
-
get(onu_id, me_class, me_inst, attr_mask, *, extended=False)¶ Get the specified attribute values.
- Parameters
onu_id (
int) – ONU id.me_class (
int) – MIB class.me_inst (
int) – MIB instance.attr_mask (
int) – requested attributes.extended (
bool) – whether an extended message has been requested.
- Return type
- Returns
Results object, including
reason,attr_maskandopt_attr_maskandattrs.
-
upload(onu_id, me_class, me_inst, *, extended=False)¶ Prepare for uploading MIBs.
This involves taking a snapshot and calculating how many subsequent
Database.upload_nextoperations will be needed.- Parameters
onu_id – ONU id.
me_class – MIB class (MUST be the ONU Data MIB class, i.e. 2).
me_inst – MIB instance (MUST be the ONU Data MIB instance, i.e. 0).
extended – whether an extended message has been requested (if so, the subsequent
Database.upload_nextoperations MUST also request extended messages).
- Return type
- Returns
Results object, including
reasonandnum_upload_nexts.
-
upload_next(onu_id, me_class, me_inst, seq_num, *, extended=False)¶ Upload the next part of a snapshot that was previously saved via
Database.upload.- Parameters
onu_id – ONU id.
me_class – MIB class (MUST be the ONU Data MIB class, i.e. 2).
me_inst – MIB instance (MUST be the ONU Data MIB instance, i.e. 0).
extended – whether an extended message has been requested (if so, the earlier
Database.uploadoperation MUST have also requested extended messages).
- Return type
- Returns
-
4.5. Support¶
Types¶
Various common data types.
-
class
obbaa_onusim.types.Name(name, description=None, *, names=None)¶ Bases:
objectName (and description) mixin class.
-
__init__(name, description=None, *, names=None)¶ Initialize self. See help(type(self)) for accurate signature.
-
__str__()¶ Return str(self).
- Return type
str
-
-
class
obbaa_onusim.types.NumberName(number, name, description=None, *, names=None)¶ Bases:
obbaa_onusim.types.NameNumber, name (and description) mixin class.
-
__init__(number, name, description=None, *, names=None)¶ Initialize self. See help(type(self)) for accurate signature.
-
__str__()¶ Return str(self).
- Return type
str
-
-
class
obbaa_onusim.types.AutoGetter¶ Bases:
objectAuto-getter mixin class.
Allows
instance._attrto be accessed (only for read access) asinstance.attr.
-
class
obbaa_onusim.types.Datum(size, default=None, fixed=None)¶ Bases:
obbaa_onusim.types.AutoGetterSingle data item class.
Defines a single data item of a given type, with support for default and fixed values, for encoding and decoding values, and for converting between user and raw values.
-
__init__(size, default=None, fixed=None)¶ Data item constructor.
- Parameters
size (
int) – size of data item in bytes.default (
Union[bytearray,int,str,None]) – default value of data item (used if no value is specified).fixed (
Union[bytearray,int,str,None]) – fixed value of data item (takes precedence over the default; any attempt to define a data item instance with a different value is an error).
Note
A default MUST currently be provided (it determines the type); this is wrong: the type should come from the subclass.
-
decode(buffer, offset)¶ Decode data item value.
- Parameters
buffer (
bytearray) – buffer from which to decode the valueoffset (
int) – byte offset within buffer at which to start decoding
- Return type
Tuple[Union[bytearray,int,str],int]- Returns
Decoded value and updated offset.
If there isn’t sufficient data in the buffer, the default value is returned
The returned value is a user value (it’s converted from the raw value)
The offset is ready to be passed to the next
decodeinvocation
-
encode(value=None)¶ Encode data item value.
- Parameters
value (
Union[bytearray,int,str,None]) – the value to be encoded- Return type
bytearray- Returns
Encoded buffer.
If value is
None, the default value is encodedThe value is converted to a raw value before encoding
-
raw_value(value)¶ Convert data item user value to raw value.
- Return type
Union[bytearray,int,str]
-
value(raw_value)¶ Convert data item raw value to user value.
- Return type
Union[bytearray,int,str]
-
__str__()¶ Return str(self).
- Return type
str
-
-
class
obbaa_onusim.types.Bool(size, default=None, fixed=None)¶ Bases:
obbaa_onusim.types.DatumBoolean data item class.
-
__init__(size, default=None, fixed=None)¶ The default defaults to false.
-
raw_value(value)¶ Convert data item user value to raw value.
- Return type
int
-
value(raw_value)¶ Convert data item raw value to user value.
- Return type
bool
-
-
class
obbaa_onusim.types.Enum(size, values=None, default=None, fixed=None)¶ Bases:
obbaa_onusim.types.DatumEnumeration data item class.
-
__init__(size, values=None, default=None, fixed=None)¶ Data item constructor.
- Parameters
size (
int) – size of data item in bytes.default (
Optional[str]) – default value of data item (used if no value is specified).fixed (
Optional[str]) – fixed value of data item (takes precedence over the default; any attempt to define a data item instance with a different value is an error).
Note
A default MUST currently be provided (it determines the type); this is wrong: the type should come from the subclass.
-
raw_value(value)¶ Convert data item user value to raw value.
- Return type
int
-
value(raw_value)¶ Convert data item raw value to user value.
- Return type
str
-
__str__()¶ Return str(self).
- Return type
str
-
-
class
obbaa_onusim.types.Bits(size, values=None, default=None, fixed=None)¶ Bases:
obbaa_onusim.types.EnumBits data item class.
-
class
obbaa_onusim.types.Number(size, default=None, fixed=None, units=None)¶ Bases:
obbaa_onusim.types.DatumNumber data item class.
-
__init__(size, default=None, fixed=None, units=None)¶ Data item constructor.
- Parameters
size (
int) – size of data item in bytes.default (
Optional[int]) – default value of data item (used if no value is specified).fixed (
Optional[int]) – fixed value of data item (takes precedence over the default; any attempt to define a data item instance with a different value is an error).
Note
A default MUST currently be provided (it determines the type); this is wrong: the type should come from the subclass.
-
raw_value(value)¶ Convert data item user value to raw value.
- Return type
int
-
value(raw_value)¶ Convert data item raw value to user value.
- Return type
int
-
-
class
obbaa_onusim.types.String(size, default=None, fixed=None)¶ Bases:
obbaa_onusim.types.DatumString data item class.
-
__init__(size, default=None, fixed=None)¶ Data item constructor.
- Parameters
size (
int) – size of data item in bytes.default (
Optional[str]) – default value of data item (used if no value is specified).fixed (
Optional[str]) – fixed value of data item (takes precedence over the default; any attempt to define a data item instance with a different value is an error).
Note
A default MUST currently be provided (it determines the type); this is wrong: the type should come from the subclass.
-
raw_value(value)¶ Convert data item user value to raw value.
- Return type
bytes
-
value(raw_value)¶ Convert data item raw value to user value.
- Return type
str
-
-
class
obbaa_onusim.types.Bytes(size, default=None, fixed=None)¶ Bases:
obbaa_onusim.types.DatumBytes data item class.
-
__init__(size, default=None, fixed=None)¶ Data item constructor.
- Parameters
size (
int) – size of data item in bytes.default (
Optional[bytes]) – default value of data item (used if no value is specified).fixed (
Optional[bytes]) – fixed value of data item (takes precedence over the default; any attempt to define a data item instance with a different value is an error).
Note
A default MUST currently be provided (it determines the type); this is wrong: the type should come from the subclass.
-
raw_value(value)¶ Convert data item user value to raw value.
- Return type
bytes
-
value(raw_value)¶ Convert data item raw value to user value.
- Return type
bytes
-
Utilities¶
Various utility functions.
-
obbaa_onusim.util.argparser(prog, description, **kwargs)¶ Argument parser helper.
- Parameters
prog (
str) – program name, typically fromsys.argv[0].description (
str) – program description, typically from__doc__.**kwargs – additional arguments; currently supported keys are
default_xxxfor argumentxxx, e.g.default_address.
- Return type
ArgumentParser- Returns
Argument parser, with common options added.
-
obbaa_onusim.util.cleandoc(docstring)¶ Clean documentation string (docstring) per PEP 257 rules.
- Parameters
docstring – supplied docstring.
- Returns
Clean docstring.
Note
This is just a wrapper around
inspect.cleandoc.
-
obbaa_onusim.util.indices(mask)¶ Attribute indices helper.
- Parameters
mask (
int) – the attribute mask for which to return the indices.- Return type
Tuple[Tuple[int,int], …]- Returns
Tuple of (
index,index_mask) tuples, whereindexis in the range 1 through 16 (inclusive).
-
obbaa_onusim.util.openfile(spec)¶ Open file helper.
- Parameters
spec (
Optional[str]) –file/mode spec; for example:
fileuses modewfile+uses modeafile+ruses moder
- Return type
Optional[IO[str]]- Returns
File object, or
Noneif spec isNone.
-
obbaa_onusim.util.toint(x)¶ String to integer conversion helper.
Supports bases 2, 8, 10 and 16.
- Parameters
x (
Any) – value to convert- Returns
Integer.
Note
It’ll throw an exception if given an invalid string.