VOL-288: Minor fixes for xPON cli in VOLTHA
Fix the following issues detected in the xPON cli:
* Missing validation for device ID
* 'show' command to display v_ont_ani, ont_ani
and v_enet does not work for specific device id
VOL-290: Use interface_stack to implement child-parent relationship for xPON interface objects
Move to an elegant approach to use child-parent relationship for xPON interface objects to
determine the OLT and ONU device id(s) for sending configuration
Change-Id: Ia26154e3fe1fba1a650c6a53f4d5232fb7369ce3
Removing extra characters
Change-Id: I11d1e86bfa8c87c1c00852a469aa5a4e21d5b49c
diff --git a/cli/main.py b/cli/main.py
index c0dbef6..8e51851 100755
--- a/cli/main.py
+++ b/cli/main.py
@@ -257,10 +257,16 @@
def do_xpon(self, line):
"""xpon <optional> [device_ID] - Enter xpon level command mode"""
device_id = line.strip()
- if not device_id:
- sub = XponCli(self.get_channel, "")
- else:
- sub = XponCli(self.get_channel, device_id)
+ if device_id:
+ stub = self.get_stub()
+ try:
+ res = stub.GetDevice(voltha_pb2.ID(id=device_id))
+ except Exception:
+ self.poutput(self.colorize('Error: ', 'red') + \
+ 'No device id ' + self.colorize(device_id, 'blue') + \
+ ' is found')
+ return
+ sub = XponCli(self.get_channel, device_id)
sub.cmdloop()
def do_pdb(self, line):
diff --git a/cli/xpon.py b/cli/xpon.py
index 61b235b..dbd7f97 100644
--- a/cli/xpon.py
+++ b/cli/xpon.py
@@ -50,65 +50,56 @@
self.get_channel = get_channel
self.device_id = device_id
self.prompt = '(' + self.colorize(
- self.colorize('voltha-xpon {}'.format(device_id), 'green'), 'bold') + ') '
+ self.colorize('voltha-xpon {}'.format(device_id), 'green'),
+ 'bold') + ') '
def cmdloop(self):
self._cmdloop()
+ def get_ref_interfaces(self, all_interfaces, ref_interfaces):
+ interface_list = []
+ if not all_interfaces:
+ return interface_list
+ if isinstance(all_interfaces[0], (ChannelgroupConfig,
+ ChannelpartitionConfig,
+ ChannelpairConfig, OntaniConfig)):
+ for interface in all_interfaces:
+ if interface.name in ref_interfaces:
+ interface_list.append(interface)
+ elif isinstance(all_interfaces[0], VOntaniConfig):
+ for interface in all_interfaces:
+ if interface.data.parent_ref in ref_interfaces:
+ interface_list.append(interface)
+ elif isinstance(all_interfaces[0], VEnetConfig):
+ for interface in all_interfaces:
+ if interface.data.v_ontani_ref in ref_interfaces:
+ interface_list.append(interface)
+ return interface_list
+
def get_interface_based_on_device(self):
stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
- temp_list = []
- cg_list = []
- cpart_list = []
- cp_list = []
- vont_list = []
- ont_list = []
- v_enet_list = []
- ct = stub.GetAllChannelterminationConfig(voltha_pb2.ID(id=self.device_id))
- cps = stub.GetAllChannelpairConfig(Empty()).channelpair_config
- cparts = stub.GetAllChannelpartitionConfig(Empty()).channelpartition_config
- cgs = stub.GetAllChannelgroupConfig(Empty()).channelgroup_config
- onts = stub.GetAllOntaniConfig(Empty()).ontani_config
- vonts = stub.GetAllVOntaniConfig(Empty()).v_ontani_config
- venets = stub.GetAllVEnetConfig(Empty()).v_enet_config
-
- for cterm in ct.channeltermination_config:
- temp_list.append(cterm.data.channelpair_ref)
- for cp in cps:
- if cp.name in temp_list:
- cp_list.append(cp)
- temp_list = []
-
- for cp in cp_list:
- temp_list.append(cp.data.channelpartition_ref)
- for cpart in cparts:
- if cpart.name in temp_list:
- cpart_list.append(cpart)
- temp_list = []
-
- for cpart in cpart_list:
- temp_list.append(cpart.data.channelgroup_ref)
- for cg in cgs:
- if cg.name in temp_list:
- cg_list.append(cg)
- temp_list = []
-
- for vont in vonts:
- if vont.data.parent_ref in cpart_list or \
- vont.data.preferred_chanpair in cp_list:
- vont_list.append(vont)
-
- for ont in onts:
- if ont.name in vont_list:
- ont_list.append(ont)
- temp_list.append(ont.name)
-
- for venet in venets:
- if venet.data.v_ontani_ref in temp_list:
- v_enet_list.append(venet)
- temp_list = []
-
- return cg_list, cpart_list, cp_list, ct.channeltermination_config, vont_list, ont_list, v_enet_list
+ channel_terminations = stub.GetAllChannelterminationConfig(
+ voltha_pb2.ID(id=self.device_id)).channeltermination_config
+ channel_pairs = self.get_ref_interfaces(
+ stub.GetAllChannelpairConfig(Empty()).channelpair_config,
+ dict((dt.data.channelpair_ref, dt) for dt in channel_terminations))
+ channel_partitions = self.get_ref_interfaces(
+ stub.GetAllChannelpartitionConfig(Empty()).channelpartition_config,
+ dict((dt.data.channelpartition_ref, dt) for dt in channel_pairs))
+ channel_groups = self.get_ref_interfaces(
+ stub.GetAllChannelgroupConfig(Empty()).channelgroup_config,
+ dict((dt.data.channelgroup_ref, dt) for dt in channel_partitions))
+ vont_anis = self.get_ref_interfaces(
+ stub.GetAllVOntaniConfig(Empty()).v_ontani_config,
+ dict((dt.name, dt) for dt in channel_partitions))
+ ont_anis = self.get_ref_interfaces(
+ stub.GetAllOntaniConfig(Empty()).ontani_config,
+ dict((dt.name, dt) for dt in vont_anis))
+ venets = self.get_ref_interfaces(
+ stub.GetAllVEnetConfig(Empty()).v_enet_config,
+ dict((dt.name, dt) for dt in vont_anis))
+ return channel_groups, channel_partitions, channel_pairs,\
+ channel_terminations, vont_anis, ont_anis, venets
do_exit = Cmd.do_quit
@@ -116,26 +107,29 @@
return self._STOP_AND_EXIT
def do_show(self, line):
- """Show detailed information of each interface based on device ID or all interfaces"""
+ """Show detailed information of each interface based on device ID
+ or all interfaces"""
stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
+ device_id = self.device_id
if line.strip():
- self.device_id = line.strip()
- if self.device_id:
- cg, cpart, cp, ct, vont, ont, venet = self.get_interface_based_on_device()
- print_pb_list_as_table("Channel Groups for device ID = {}:".format(self.device_id),
- cg, {}, self.poutput)
- print_pb_list_as_table("Channel Partitions for device ID = {}:".format(self.device_id),
- cpart, {}, self.poutput)
- print_pb_list_as_table("Channel Pairs: for device ID = {}:".format(self.device_id),
- cp, {}, self.poutput)
- print_pb_list_as_table("Channel Terminations for device ID = {}:".format(self.device_id),
- ct, {}, self.poutput)
- print_pb_list_as_table("VOnt Anis for device ID = {}:".format(self.device_id),
- vont, {}, self.poutput)
- print_pb_list_as_table("Ont Anis for device ID = {}:".format(self.device_id),
- ont, {}, self.poutput)
- print_pb_list_as_table("VEnets for device ID = {}:".format(self.device_id),
- venet, {}, self.poutput)
+ device_id = line.strip()
+ if device_id:
+ cg, cpart, cp, ct, vont, ont, venet = \
+ self.get_interface_based_on_device()
+ print_pb_list_as_table("Channel Groups for device ID = {}:"
+ .format(device_id), cg, {}, self.poutput)
+ print_pb_list_as_table("Channel Partitions for device ID = {}:"
+ .format(device_id),cpart, {}, self.poutput)
+ print_pb_list_as_table("Channel Pairs: for device ID = {}:"
+ .format(device_id), cp, {}, self.poutput)
+ print_pb_list_as_table("Channel Terminations for device ID = {}:"
+ .format(device_id), ct, {}, self.poutput)
+ print_pb_list_as_table("VOnt Anis for device ID = {}:"
+ .format(device_id), vont, {}, self.poutput)
+ print_pb_list_as_table("Ont Anis for device ID = {}:"
+ .format(device_id), ont, {}, self.poutput)
+ print_pb_list_as_table("VEnets for device ID = {}:"
+ .format(device_id), venet, {}, self.poutput)
else:
interface = stub.GetAllChannelgroupConfig(Empty())
print_pb_list_as_table("Channel Groups:",
@@ -151,10 +145,12 @@
{}, self.poutput)
devices = stub.ListDevices(Empty())
for d in devices.items:
- interface = stub.GetAllChannelterminationConfig(voltha_pb2.ID(id=d.id))
- print_pb_list_as_table("Channel Terminations for device ID = {}:".format(d.id),
- interface.channeltermination_config,
- {}, self.poutput)
+ interface = stub.GetAllChannelterminationConfig(
+ voltha_pb2.ID(id=d.id))
+ print_pb_list_as_table(
+ "Channel Terminations for device ID = {}:"
+ .format(d.id), interface.channeltermination_config,
+ {}, self.poutput)
interface = stub.GetAllVOntaniConfig(Empty())
print_pb_list_as_table("VOnt Anis:",
interface.v_ontani_config,
@@ -171,16 +167,17 @@
def help_channel_group(self):
self.poutput(
'''
-channel_group [get | create | update | delete] [-n <name>] [-d <description>] [-a <admin state>]
- [-l <link up down trap enable type>] [-p <polling period>] [-s <system id>]
- [-r <raman mitigation>]
+channel_group [get | create | update | delete] [-n <name>] [-d <description>]
+ [-a <admin state>] [-l <link up down trap enable type>]
+ [-p <polling period>] [-s <system id>] [-r <raman mitigation>]
get: displays existing channel groups
Required flags: None
-create: creates channel group with the parameters specified with -n, -d, -a, -l, -p, -s and -r.
+create: creates channel group with the parameters specified with -n, -d, -a,
+ -l, -p, -s and -r.
Required flags: <name>
-update: updates existing channel group specified with parameter -n by changing its parameter values
- specified with -d, -a, -l, -p, -s and -r.
+update: updates existing channel group specified with parameter -n by changing
+ its parameter values specified with -d, -a, -l, -p, -s and -r.
Required flags: <name>
delete: deletes channel group specified with parameter -n.
Required flags: <name>
@@ -188,7 +185,7 @@
-n: <string> name of channel group.
-d: <string> description of channel group.
-a: <string> admin state of channel group.
--l: <enum> link up down trap enable type.
+-l: <enum> link up down trap enable type.
-p: <int> polling period for channel group.
-s: <string> system id for channel group.
-r: <enum> raman mitigation for channel group.
@@ -203,21 +200,28 @@
make_option('-n', '--name', action="store", dest='name', type='string',
help='name of channel group', default=None),
make_option('-d', '--description', action="store", dest='description',
- type='string', help='description of channel group', default=None),
- make_option('-a', '--admin_state', action="store", dest='enabled', type='string',
- help='admin state of channel group', default=None),
- make_option('-l', '--trap', action="store", dest='link_up_down_trap_enable',
- type='string', help='link up down trap enable type', default=None),
+ type='string', help='description of channel group',
+ default=None),
+ make_option('-a', '--admin_state', action="store", dest='enabled',
+ type='string', help='admin state of channel group',
+ default=None),
+ make_option('-l', '--trap', action="store",
+ dest='link_up_down_trap_enable', type='string',
+ help='link up down trap enable type', default=None),
make_option('-p', '--pp', action='store', dest='polling_period',
- type='int', help='polling period of channel group', default=None),
+ type='int', help='polling period of channel group',
+ default=None),
make_option('-s', '--sid', action='store', dest='system_id',
- type='string', help='system id of channel group', default=None),
+ type='string', help='system id of channel group',
+ default=None),
make_option('-r', '--rm', action='store', dest='raman_mitigation',
- type='string', help='raman mitigation of channel group', default=None),
+ type='string', help='raman mitigation of channel group',
+ default=None),
])
def do_channel_group(self, line, opts):
- """channel group get, create -flags <attributes>, update -flags <attributes>, delete -n <name>"""
+ """channel group get, create -flags <attributes>,
+ update -flags <attributes>, delete -n <name>"""
# Ensure that a valid sub-command was provided
if line.strip() not in {"get", "create", "update", "delete"}:
self.poutput(self.colorize('Error: ', 'red') + \
@@ -229,8 +233,10 @@
if line.strip() == "get":
if self.device_id:
- cg, cpart, cp, ct, vont, ont, venet = self.get_interface_based_on_device()
- print_pb_list_as_table("Channel Groups for device ID = {}:".format(self.device_id),
+ cg, cpart, cp, ct, vont, ont, venet = \
+ self.get_interface_based_on_device()
+ print_pb_list_as_table("Channel Groups for device ID = {}:"
+ .format(self.device_id),
cg, {}, self.poutput)
else:
interface = stub.GetAllChannelgroupConfig(Empty())
@@ -238,15 +244,6 @@
interface.channelgroup_config,
{}, self.poutput)
return
- #if not opts.name:
- # self.poutput(self.colorize('Error: ', 'red') + \
- # self.colorize(self.colorize('Name is required parameter', 'blue'),
- # 'bold'))
- # return
- #if interface_instance:
- # self.poutput(self.colorize('Unable. Please commit or reset: ', 'yellow') + \
- # self.colorize(interface_instance.name, 'blue'))
- # return
interface_instance = ChannelgroupConfig(name = opts.name)
interface_instance.interface.name = opts.name
if opts.description:
@@ -258,18 +255,22 @@
elif opts.enabled == "down":
interface_instance.interface.enabled = False
else:
- self.poutput(self.colorize('Error: ', 'red') + \
- self.colorize(self.colorize('Invalid admin state parameter for channel group', 'blue'),
- 'bold'))
+ self.poutput(
+ self.colorize('Error: ', 'red') + self.colorize(
+ self.colorize(
+ 'Invalid admin state parameter for channel group',
+ 'blue'), 'bold'))
return
if opts.link_up_down_trap_enable:
types = ["trap_disabled", "trap_enabled"]
try:
assert opts.link_up_down_trap_enable in types, \
- 'Invalid Enum value for Channel Group link up down trap enable type \'{}\''\
- .format(opts.link_up_down_trap_enable)
+ 'Invalid Enum value for Channel Group link up down trap \
+ enable type \'{}\''.format(opts.link_up_down_trap_enable)
interface_instance.interface.link_up_down_trap_enable = \
- ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.values_by_name[opts.link_up_down_trap_enable.upper()].number
+ ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\
+ values_by_name[opts.link_up_down_trap_enable.upper()]\
+ .number
except AssertionError, e:
self.poutput(self.colorize('Error: ', 'red') + \
self.colorize(self.colorize(e.message, 'blue'),
@@ -282,9 +283,11 @@
raman_mitigations = ["raman_none", "raman_miller", "raman_8b10b"]
try:
assert opts.raman_mitigation in raman_mitigations, \
- 'Invalid Enum value for Channel Group raman mitigation \'{}\''.format(opts.raman_mitigation)
+ 'Invalid Enum value for Channel Group raman mitigation\
+ \'{}\''.format(opts.raman_mitigation)
interface_instance.data.raman_mitigation = \
- bbf_fiber_types_pb2._RAMANMITIGATIONTYPE.values_by_name[opts.raman_mitigation.upper()].number
+ bbf_fiber_types_pb2._RAMANMITIGATIONTYPE.\
+ values_by_name[opts.raman_mitigation.upper()].number
except AssertionError, e:
self.poutput(self.colorize('Error: ', 'red') + \
self.colorize(self.colorize(e.message, 'blue'),
@@ -304,17 +307,22 @@
def help_channel_partition(self):
self.poutput(
'''
-channel_partition [get | create | update | delete] [-n <name>] [-d <description>] [-a <admin state>]
- [-l <link up down trap enable type>] [-r <differential fiber distance>]
- [-o <closest ont distance>] [-f <fec downstream>] [-m <multicast aes indicator>]
- [-u <authentication method>] [-c <channel group reference>]
+channel_partition [get | create | update | delete] [-n <name>]
+ [-d <description>] [-a <admin state>]
+ [-l <link up down trap enable type>]
+ [-r <differential fiber distance>]
+ [-o <closest ont distance>] [-f <fec downstream>]
+ [-m <multicast aes indicator>] [-u <authentication method>]
+ [-c <channel group reference>]
get: displays existing channel partitions
Required flags: None
-create: creates channel partition with the parameters specified with -n, -d, -a, -l, -r, -o, -f, -m, -u and -c.
+create: creates channel partition with the parameters specified with -n, -d,
+ -a, -l, -r, -o, -f, -m, -u and -c.
Required flags: <name>, <channel group reference>
-update: updates existing channel partition specified with parameter -n by changing its parameter values
- specified with -d, -a, -l, -r, -o, -f, -m, -u and -c.
+update: updates existing channel partition specified with parameter -n by
+ changing its parameter values specified with -d, -a, -l, -r, -o, -f,
+ -m, -u and -c.
Required flags: <name>
delete: deletes channel group specified with parameter -n.
Required flags: <name>
@@ -332,7 +340,8 @@
Example:
-channel_partition create -n cpart-1-1 -a up -r 20 -o 0 -f false -m false -u serial_number -c cg-1
+channel_partition create -n cpart-1-1 -a up -r 20 -o 0 -f false -m false
+ -u serial_number -c cg-1
'''
)
@@ -340,27 +349,40 @@
make_option('-n', '--name', action="store", dest='name', type='string',
help='name of channel partition', default=None),
make_option('-d', '--description', action="store", dest='description',
- type='string', help='description of channel partition', default=None),
- make_option('-a', '--admin_state', action="store", dest='enabled', type='string',
- help='admin state of channel partition', default=None),
- make_option('-l', '--trap', action="store", dest='link_up_down_trap_enable',
- type='string', help='link up down trap enable type', default=None),
- make_option('-r', '--diff_fib_dist', action='store', dest='differential_fiber_distance',
- type='int', help='differential fiber distance', default=None),
- make_option('-o', '--ont_dist', action='store', dest='closest_ont_distance',
- type='int', help='closest ont distance', default=None),
+ type='string', help='description of channel partition',
+ default=None),
+ make_option('-a', '--admin_state', action="store", dest='enabled',
+ type='string', help='admin state of channel partition',
+ default=None),
+ make_option('-l', '--trap', action="store",
+ dest='link_up_down_trap_enable', type='string',
+ help='link up down trap enable type', default=None),
+ make_option('-r', '--diff_fib_dist', action='store',
+ dest='differential_fiber_distance', type='int',
+ help='differential fiber distance', default=None),
+ make_option('-o', '--ont_dist', action='store',
+ dest='closest_ont_distance', type='int',
+ help='closest ont distance', default=None),
make_option('-f', '--fec_ds', action='store', dest='fec_downstream',
- type='string', help='forward and error correction downstream', default=None),
- make_option('-m', '--mc_aes', action='store', dest='multicast_aes_indicator',
- type='string', help='multicast aes indicator of channel partition', default=None),
- make_option('-u', '--auth', action='store', dest='authentication_method',
- type='string', help='authentication method', default=None),
+ type='string',
+ help='forward and error correction downstream',
+ default=None),
+ make_option('-m', '--mc_aes', action='store',
+ dest='multicast_aes_indicator', type='string',
+ help='multicast aes indicator of channel partition',
+ default=None),
+ make_option('-u', '--auth', action='store',
+ dest='authentication_method', type='string',
+ help='authentication method', default=None),
make_option('-c', '--cg_ref', action='store', dest='channelgroup_ref',
- type='string', help='channel group reference for this channel partition', default=None),
+ type='string',
+ help='channel group reference for this channel partition',
+ default=None),
])
def do_channel_partition(self, line, opts):
- """channel partition get, create -flags <attributes>, update -flags <attributes>, delete -n <name>"""
+ """channel partition get, create -flags <attributes>,
+ update -flags <attributes>, delete -n <name>"""
# Ensure that a valid sub-command was provided
if line.strip() not in {"get", "create", "update", "delete"}:
self.poutput(self.colorize('Error: ', 'red') + \
@@ -372,9 +394,11 @@
if line.strip() == "get":
if self.device_id:
- cg, cpart, cp, ct, vont, ont, venet = self.get_interface_based_on_device()
- print_pb_list_as_table("Channel Partitions for device ID = {}:".format(self.device_id),
- cpart, {}, self.poutput)
+ cg, cpart, cp, ct, vont, ont, venet = \
+ self.get_interface_based_on_device()
+ print_pb_list_as_table("Channel Partitions for device ID = {}:"
+ .format(self.device_id), cpart, {},
+ self.poutput)
else:
interface = stub.GetAllChannelpartitionConfig(Empty())
print_pb_list_as_table("Channel Partitions:",
@@ -393,18 +417,22 @@
elif opts.enabled == "down":
interface_instance.interface.enabled = False
else:
- self.poutput(self.colorize('Error: ', 'red') + \
- self.colorize(self.colorize('Invalid admin state parameter for channel partition', 'blue'),
- 'bold'))
+ self.poutput(
+ self.colorize('Error: ', 'red') + self.colorize(
+ self.colorize('Invalid admin state parameter for \
+ channel partition', 'blue'), 'bold'))
return
if opts.link_up_down_trap_enable:
types = ["trap_disabled", "trap_enabled"]
try:
assert opts.link_up_down_trap_enable in types, \
- 'Invalid Enum value for Channel Partition link up down trap enable type \'{}\''\
+ 'Invalid Enum value for Channel Partition link up \
+ down trap enable type \'{}\''\
.format(opts.link_up_down_trap_enable)
interface_instance.interface.link_up_down_trap_enable = \
- ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.values_by_name[opts.link_up_down_trap_enable.upper()].number
+ ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\
+ values_by_name[opts.link_up_down_trap_enable.upper()].\
+ number
except AssertionError, e:
self.poutput(self.colorize('Error: ', 'red') + \
self.colorize(self.colorize(e.message, 'blue'),
@@ -412,17 +440,19 @@
return
if opts.differential_fiber_distance:
- interface_instance.data.differential_fiber_distance = opts.differential_fiber_distance
+ interface_instance.data.differential_fiber_distance = \
+ opts.differential_fiber_distance
if opts.closest_ont_distance:
- interface_instance.data.closest_ont_distance = opts.closest_ont_distance
+ interface_instance.data.closest_ont_distance = \
+ opts.closest_ont_distance
if opts.fec_downstream:
if opts.fec_downstream == 'true':
interface_instance.data.fec_downstream = True
elif opts.fec_downstream == 'false':
interface_instance.data.fec_downstream = False
else:
- m = 'Invalid boolean value for Channel Partition fec_downstream \'{}\''\
- .format(opts.fec_downstream)
+ m = 'Invalid boolean value for Channel Partition \
+ fec_downstream \'{}\''.format(opts.fec_downstream)
self.poutput(self.colorize('Error: ', 'red') + \
self.colorize(self.colorize(m, 'blue'),
'bold'))
@@ -433,19 +463,24 @@
elif opts.multicast_aes_indicator == 'false':
interface_instance.data.multicast_aes_indicator = False
else:
- m = 'Invalid boolean value for Channel Partition multicast_aes_indicator \'{}\''\
- .format(opts.multicast_aes_indicator)
+ m = 'Invalid boolean value for Channel Partition \
+ multicast_aes_indicator \'{}\''.format(
+ opts.multicast_aes_indicator)
self.poutput(self.colorize('Error: ', 'red') + \
self.colorize(self.colorize(m, 'blue'),
'bold'))
return
if opts.authentication_method:
- auth_method_types = ["serial_number", "loid", "registration_id", "omci", "dot1x"]
+ auth_method_types = \
+ ["serial_number", "loid", "registration_id", "omci", "dot1x"]
try:
assert opts.authentication_method in auth_method_types, \
- 'Invalid Enum value for Channel Partition authentication method \'{}\''.format(opts.authentication_method)
+ 'Invalid Enum value for Channel Partition \
+ authentication method \'{}\''.format(
+ opts.authentication_method)
interface_instance.data.authentication_method = \
- bbf_fiber_types_pb2._AUTHMETHODTYPE.values_by_name[opts.authentication_method.upper()].number
+ bbf_fiber_types_pb2._AUTHMETHODTYPE.\
+ values_by_name[opts.authentication_method.upper()].number
except AssertionError, e:
self.poutput(self.colorize('Error: ', 'red') + \
self.colorize(self.colorize(e.message, 'blue'),
@@ -465,17 +500,20 @@
def help_channel_pair(self):
self.poutput(
'''
-channel_pair [get | create | update | delete] [-n <name>] [-d <description>] [-a <admin state>]
- [-l <link up down trap enable type>] [-r <channel pair line rate>]
- [-t <channel pair type>] [-g <channel group reference>] [-i <gpon pon id interval>]
+channel_pair [get | create | update | delete] [-n <name>] [-d <description>]
+ [-a <admin state>] [-l <link up down trap enable type>]
+ [-r <channel pair line rate>] [-t <channel pair type>]
+ [-g <channel group reference>] [-i <gpon pon id interval>]
[-p <channel partition reference>] [-o <gpon pon id odn class>]
get: displays existing channel pairs
Required flags: None
-create: creates channel pair with the parameters specified with -n, -d, -a, -l, -r, -t, -g, -i, -p and -o.
+create: creates channel pair with the parameters specified with -n, -d, -a,
+ -l, -r, -t, -g, -i, -p and -o.
Required flags: <name>, <channel pair type>
-update: updates existing channel pair specified with parameter -n by changing its parameter values
- specified with -d, -a, -l, -r, -t, -g, -i, -p and -o.
+update: updates existing channel pair specified with parameter -n by changing
+ its parameter values specified with -d, -a, -l, -r, -t, -g, -i, -p
+ and -o.
Required flags: <name>
delete: deletes channel group specified with parameter -n.
Required flags: <name>
@@ -493,7 +531,8 @@
Example:
-channel_pair create -n cp-1 -a up -r unplanned_cp_speed -t channelpair -g cg-1 -i 0 -p cpart-1-1 -o class_a
+channel_pair create -n cp-1 -a up -r unplanned_cp_speed -t channelpair -g cg-1
+ -i 0 -p cpart-1-1 -o class_a
'''
)
@@ -501,27 +540,36 @@
make_option('-n', '--name', action="store", dest='name', type='string',
help='name of channel pair', default=None),
make_option('-d', '--description', action="store", dest='description',
- type='string', help='description of channel pair', default=None),
- make_option('-a', '--admin_state', action="store", dest='enabled', type='string',
- help='admin state of channel pair', default=None),
- make_option('-l', '--trap', action="store", dest='link_up_down_trap_enable',
- type='string', help='link up down trap enable type', default=None),
- make_option('-r', '--cp_line_rate', action='store', dest='channelpair_linerate',
- type='string', help='channel pair linerate', default=None),
+ type='string', help='description of channel pair',
+ default=None),
+ make_option('-a', '--admin_state', action="store", dest='enabled',
+ type='string', help='admin state of channel pair',
+ default=None),
+ make_option('-l', '--trap', action="store",
+ dest='link_up_down_trap_enable', type='string',
+ help='link up down trap enable type', default=None),
+ make_option('-r', '--cp_line_rate', action='store',
+ dest='channelpair_linerate', type='string',
+ help='channel pair linerate', default=None),
make_option('-t', '--cp_type', action='store', dest='channelpair_type',
type='string', help='channel pair type', default=None),
make_option('-g', '--cg_ref', action='store', dest='channelgroup_ref',
- type='string', help='channel group reference', default=None),
- make_option('-i', '--interval', action='store', dest='gpon_ponid_interval',
- type='int', help='gpon pon id interval', default=None),
- make_option('-p', '--cpart_ref', action='store', dest='channelpartition_ref',
- type='string', help='channel partition reference', default=None),
- make_option('-o', '--odn_class', action='store', dest='gpon_ponid_odn_class',
- type='string', help='gpon pon id odn class', default=None),
+ type='string', help='channel group reference',
+ default=None),
+ make_option('-i', '--interval', action='store',
+ dest='gpon_ponid_interval', type='int',
+ help='gpon pon id interval', default=None),
+ make_option('-p', '--cpart_ref', action='store',
+ dest='channelpartition_ref', type='string',
+ help='channel partition reference', default=None),
+ make_option('-o', '--odn_class', action='store',
+ dest='gpon_ponid_odn_class', type='string',
+ help='gpon pon id odn class', default=None),
])
def do_channel_pair(self, line, opts):
- """channel pair get, create -flags <attributes>, update -flags <attributes>, delete -n <name>"""
+ """channel pair get, create -flags <attributes>,
+ update -flags <attributes>, delete -n <name>"""
# Ensure that a valid sub-command was provided
if line.strip() not in {"get", "create", "update", "delete"}:
self.poutput(self.colorize('Error: ', 'red') + \
@@ -533,9 +581,11 @@
if line.strip() == "get":
if self.device_id:
- cg, cpart, cp, ct, vont, ont, venet = self.get_interface_based_on_device()
- print_pb_list_as_table("Channel Pairs for device ID = {}:".format(self.device_id),
- cp, {}, self.poutput)
+ cg, cpart, cp, ct, vont, ont, venet = \
+ self.get_interface_based_on_device()
+ print_pb_list_as_table("Channel Pairs for device ID = {}:"
+ .format(self.device_id), cp, {},
+ self.poutput)
else:
interface = stub.GetAllChannelpairConfig(Empty())
print_pb_list_as_table("Channel Pairs:",
@@ -554,18 +604,22 @@
elif opts.enabled == "down":
interface_instance.interface.enabled = False
else:
- self.poutput(self.colorize('Error: ', 'red') + \
- self.colorize(self.colorize('Invalid admin state parameter for channel pair', 'blue'),
- 'bold'))
+ self.poutput(
+ self.colorize('Error: ', 'red') + self.colorize(
+ self.colorize('Invalid admin state parameter for \
+ channel pair', 'blue'), 'bold'))
return
if opts.link_up_down_trap_enable:
types = ["trap_disabled", "trap_enabled"]
try:
assert opts.link_up_down_trap_enable in types, \
- 'Invalid Enum value for Channel Pair link up down trap enable type \'{}\''\
- .format(opts.link_up_down_trap_enable)
+ 'Invalid Enum value for Channel Pair link up down \
+ trap enable type \'{}\''.format(
+ opts.link_up_down_trap_enable)
interface_instance.interface.link_up_down_trap_enable = \
- ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.values_by_name[opts.link_up_down_trap_enable.upper()].number
+ ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\
+ values_by_name[opts.link_up_down_trap_enable.upper()].\
+ number
except AssertionError, e:
self.poutput(self.colorize('Error: ', 'red') + \
self.colorize(self.colorize(e.message, 'blue'),
@@ -573,22 +627,28 @@
return
if opts.channelpair_linerate:
- interface_instance.data.channelpair_linerate = opts.channelpair_linerate
+ interface_instance.data.channelpair_linerate = \
+ opts.channelpair_linerate
if opts.channelpair_type:
interface_instance.data.channelpair_type = opts.channelpair_type
if opts.channelgroup_ref:
interface_instance.data.channelgroup_ref = opts.channelgroup_ref
if opts.gpon_ponid_interval:
- interface_instance.data.gpon_ponid_interval = opts.gpon_ponid_interval
+ interface_instance.data.gpon_ponid_interval = \
+ opts.gpon_ponid_interval
if opts.channelpartition_ref:
- interface_instance.data.channelpartition_ref = opts.channelpartition_ref
+ interface_instance.data.channelpartition_ref = \
+ opts.channelpartition_ref
if opts.gpon_ponid_odn_class:
- class_types = ["class_a", "class_b", "class_b_plus", "class_c", "class_c_plus", "class_auto"]
+ class_types = ["class_a", "class_b", "class_b_plus", "class_c",
+ "class_c_plus", "class_auto"]
try:
assert opts.gpon_ponid_odn_class in class_types, \
- 'Invalid enum value for Channel Pair gpon pon id odn class \'{}\''.format(opts.gpon_ponid_odn_class)
+ 'Invalid enum value for Channel Pair gpon pon id odn \
+ class \'{}\''.format(opts.gpon_ponid_odn_class)
interface_instance.data.gpon_ponid_odn_class = \
- bbf_fiber_types_pb2._PONIDODNCLASSTYPE.values_by_name[opts.gpon_ponid_odn_class.upper()].number
+ bbf_fiber_types_pb2._PONIDODNCLASSTYPE.\
+ values_by_name[opts.gpon_ponid_odn_class.upper()].number
except AssertionError, e:
self.poutput(self.colorize('Error: ', 'red') + \
self.colorize(self.colorize(e.message, 'blue'),
@@ -607,19 +667,24 @@
self.poutput(
'''
channel_termination [get | create | update | delete] [-i <id>] [-n <name>]
- [-d <description>] [-a <admin state>] [-l <link up down trap enable type>]
- [-r <channel pair reference>] [-m <meant for type_b primary role>]
- [-w <ngpon2 time wavelength division multiplexing admin label>]
+ [-d <description>] [-a <admin state>]
+ [-l <link up down trap enable type>]
+ [-r <channel pair reference>]
+ [-m <meant for type_b primary role>]
+ [-w <ngpon2 time wavelength division multiplexing
+ admin label>]
[-p <ngpon2 ptp admin label>] [-s <xgs pon id>]
[-x <xgpon pon id>] [-g <gpon pon id>] [-t <pon tag>]
[-b <ber calc period>] [-l <location>] [-u <url to reach>]
get: displays existing channel pairs
Required flags: None
-create: creates channel pair with the parameters specified with -i -n, -d, -a, -l, -r, -m, -w, -p, -s, -x, -g, -t, -b, -c and -u
+create: creates channel pair with the parameters specified with -i -n, -d, -a,
+ -l, -r, -m, -w, -p, -s, -x, -g, -t, -b, -c and -u
Required flags: <id>, <name>
-update: updates existing channel termination specified with -i and -n parameters by changing
- its parameter values specified with -d, -a, -l, -r, -m, -w, -p, -s, -x, -g, -b, -c, and -u
+update: updates existing channel termination specified with -i and -n
+ parameters by changing its parameter values specified with -d, -a, -l,
+ -r, -m, -w, -p, -s, -x, -g, -b, -c, and -u
Required flags: <id>, <name>
delete: deletes channel termination specified with parameter -i and -n.
Required flags: <id>, <name>
@@ -643,7 +708,8 @@
Example:
-channel_termination create -i f90bb953f988 -n cterm-1 -a up -r cp-1 -m false -w 0 -p 0 -s 0 -x 0 -b 0 -c raleigh -u localhost
+channel_termination create -i f90bb953f988 -n cterm-1 -a up -r cp-1 -m false
+ -w 0 -p 0 -s 0 -x 0 -b 0 -c raleigh -u localhost
'''
)
@@ -654,19 +720,29 @@
make_option('-n', '--name', action="store", dest='name', type='string',
help='name of channel pair', default=None),
make_option('-d', '--description', action="store", dest='description',
- type='string', help='description of channel termination', default=None),
- make_option('-a', '--admin_state', action="store", dest='enabled', type='string',
- help='admin state of channel termination', default=None),
- make_option('-l', '--trap', action="store", dest='link_up_down_trap_enable',
- type='string', help='link up down trap enable type', default=None),
+ type='string', help='description of channel termination',
+ default=None),
+ make_option('-a', '--admin_state', action="store", dest='enabled',
+ type='string', help='admin state of channel termination',
+ default=None),
+ make_option('-l', '--trap', action="store",
+ dest='link_up_down_trap_enable', type='string',
+ help='link up down trap enable type', default=None),
make_option('-r', '--cp_ref', action='store', dest='channelpair_ref',
- type='string', help='channel pair reference for this channel termination', default=None),
- make_option('-m', '--type_b', action='store', dest='meant_for_type_b_primary_role',
- type='string', help='meant for type_b primary role', default=None),
- make_option('-w', '--t_w_d_m', action='store', dest='ngpon2_twdm_admin_label',
- type='int', help='ngpon2 time wavelength division multiplexing admin label', default=None),
- make_option('-p', '--ptp', action='store', dest='ngpon2_ptp_admin_label',
- type='int', help='ngpon2 precision time protocol admin label', default=None),
+ type='string',
+ help='channel pair reference for this channel termination',
+ default=None),
+ make_option('-m', '--type_b', action='store',
+ dest='meant_for_type_b_primary_role', type='string',
+ help='meant for type_b primary role', default=None),
+ make_option('-w', '--t_w_d_m', action='store',
+ dest='ngpon2_twdm_admin_label', type='int',
+ help='ngpon2 time wavelength division multiplexing admin \
+ label', default=None),
+ make_option('-p', '--ptp', action='store',
+ dest='ngpon2_ptp_admin_label', type='int',
+ help='ngpon2 precision time protocol admin label',
+ default=None),
make_option('-s', '--xgs', action='store', dest='xgs_ponid',
type='int', help='xgs pon id', default=None),
make_option('-x', '--xgpon', action='store', dest='xgpon_ponid',
@@ -676,15 +752,19 @@
make_option('-t', '--pon', action='store', dest='pon_tag',
type='string', help='pon tag', default=None),
make_option('-b', '--ber', action='store', dest='ber_calc_period',
- type='int', help='bit error rate calculation period', default=None),
+ type='int', help='bit error rate calculation period',
+ default=None),
make_option('-c', '--location', action='store', dest='location',
- type='string', help='location of channel termination', default=None),
+ type='string', help='location of channel termination',
+ default=None),
make_option('-u', '--url', action='store', dest='url_to_reach',
- type='string', help='url to reach channel termination', default=None),
+ type='string', help='url to reach channel termination',
+ default=None),
])
def do_channel_termination(self, line, opts):
- """channel termination get, create -flags <attributes>, update -flags <attributes>, delete -i <id> -n <name>"""
+ """channel termination get, create -flags <attributes>,
+ update -flags <attributes>, delete -i <id> -n <name>"""
# Ensure that a valid sub-command was provided
if line.strip() not in {"get", "create", "update", "delete"}:
self.poutput(self.colorize('Error: ', 'red') + \
@@ -696,23 +776,30 @@
if line.strip() == "get":
if self.device_id:
- cg, cpart, cp, ct, vont, ont, venet = self.get_interface_based_on_device()
- print_pb_list_as_table("Channel Terminations for device ID = {}:".format(self.device_id),
- ct, {}, self.poutput)
+ cg, cpart, cp, ct, vont, ont, venet = \
+ self.get_interface_based_on_device()
+ print_pb_list_as_table(
+ "Channel Terminations for device ID = {}:"
+ .format(self.device_id), ct, {}, self.poutput)
elif opts.id:
- ct = stub.GetAllChannelterminationConfig(voltha_pb2.ID(id=opts.id)).channeltermination_config
- print_pb_list_as_table("Channel Terminations for device ID = {}:".format(opts.id),
+ ct = stub.GetAllChannelterminationConfig(
+ voltha_pb2.ID(id=opts.id)).channeltermination_config
+ print_pb_list_as_table(
+ "Channel Terminations for device ID = {}:".format(opts.id),
ct, {}, self.poutput)
else:
devices = stub.ListDevices(Empty())
for d in devices.items:
- interface = stub.GetAllChannelterminationConfig(voltha_pb2.ID(id=d.id))
- print_pb_list_as_table("Channel Terminations for device ID = {}:".format(d.id),
- interface.channeltermination_config,
- {}, self.poutput)
+ interface = stub.GetAllChannelterminationConfig(
+ voltha_pb2.ID(id=d.id))
+ print_pb_list_as_table(
+ "Channel Terminations for device ID = {}:"
+ .format(d.id), interface.channeltermination_config,
+ {}, self.poutput)
return
- interface_instance = ChannelterminationConfig(id = opts.id, name = opts.name)
+ interface_instance = ChannelterminationConfig(
+ id = opts.id, name = opts.name)
interface_instance.interface.name = opts.name
if opts.description:
interface_instance.interface.description = opts.description
@@ -723,18 +810,22 @@
elif opts.enabled == "down":
interface_instance.interface.enabled = False
else:
- self.poutput(self.colorize('Error: ', 'red') + \
- self.colorize(self.colorize('Invalid admin state parameter for channel termination', 'blue'),
- 'bold'))
+ self.poutput(
+ self.colorize('Error: ', 'red') + self.colorize(
+ self.colorize('Invalid admin state parameter for \
+ channel termination', 'blue'), 'bold'))
return
if opts.link_up_down_trap_enable:
types = ["trap_disabled", "trap_enabled"]
try:
assert opts.link_up_down_trap_enable in types, \
- 'Invalid Enum value for Channel Termination link up down trap enable type \'{}\''\
- .format(opts.link_up_down_trap_enable)
+ 'Invalid Enum value for Channel Termination link up \
+ down trap enable type \'{}\''.format(
+ opts.link_up_down_trap_enable)
interface_instance.interface.link_up_down_trap_enable = \
- ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.values_by_name[opts.link_up_down_trap_enable.upper()].number
+ ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\
+ values_by_name[opts.link_up_down_trap_enable.upper()].\
+ number
except AssertionError, e:
self.poutput(self.colorize('Error: ', 'red') + \
self.colorize(self.colorize(e.message, 'blue'),
@@ -749,16 +840,19 @@
elif opts.meant_for_type_b_primary_role == 'false':
interface_instance.data.meant_for_type_b_primary_role = False
else:
- m = 'Invalid boolean value for Channel Termination meant_for_type_b_primary_role \'{}\''\
- .format(opts.meant_for_type_b_primary_role)
+ m = 'Invalid boolean value for Channel Termination \
+ meant_for_type_b_primary_role \'{}\''.format(
+ opts.meant_for_type_b_primary_role)
self.poutput(self.colorize('Error: ', 'red') + \
self.colorize(self.colorize(m, 'blue'),
'bold'))
return
if opts.ngpon2_twdm_admin_label:
- interface_instance.data.ngpon2_twdm_admin_label = opts.ngpon2_twdm_admin_label
+ interface_instance.data.ngpon2_twdm_admin_label = \
+ opts.ngpon2_twdm_admin_label
if opts.ngpon2_ptp_admin_label:
- interface_instance.data.ngpon2_ptp_admin_label = opts.ngpon2_ptp_admin_label
+ interface_instance.data.ngpon2_ptp_admin_label = \
+ opts.ngpon2_ptp_admin_label
if opts.xgs_ponid:
interface_instance.data.xgs_ponid = opts.xgs_ponid
if opts.xgpon_ponid:
@@ -785,18 +879,21 @@
def help_vont_ani(self):
self.poutput(
'''
-vont_ani [get | create | update | delete] [-n <name>] [-d <description>] [-a <admin state>]
- [-l <link up down trap enable type>] [-p <parent reference>]
- [-s <expected serial number>] [-i <expected registration id>]
- [-r <preferred channel pair>] [-t <protection channel pair>]
- [-u <upstream channel speed>] [-o <onu id>]
+vont_ani [get | create | update | delete] [-n <name>] [-d <description>]
+ [-a <admin state>] [-l <link up down trap enable type>]
+ [-p <parent reference>] [-s <expected serial number>]
+ [-i <expected registration id>] [-r <preferred channel pair>]
+ [-t <protection channel pair>] [-u <upstream channel speed>]
+ [-o <onu id>]
get: displays existing vont anis
Required flags: None
-create: creates vont ani with the parameters specified with -n, -d, -a, -l, -p, -s, -i, -r, -t, -u and -o.
+create: creates vont ani with the parameters specified with -n, -d, -a, -l,
+ -p, -s, -i, -r, -t, -u and -o.
Required flags: <name>
-update: updates existing vont ani specified with parameter -n by changing its parameter values
- specified with -d, -a, -l, -p, -s, -i, -r, -t, -u and -o.
+update: updates existing vont ani specified with parameter -n by changing its
+ parameter values specified with -d, -a, -l, -p, -s, -i, -r, -t, -u
+ and -o.
Required flags: <name>
delete: deletes vont ani specified with parameter -n.
Required flags: <name>
@@ -815,7 +912,8 @@
Example:
-vont_ani create -n ontani-1-1-1 -a up -p cpart-1-1 -s ALCL00000001 -r cp-1 -u 0 -o 1
+vont_ani create -n ontani-1-1-1 -a up -p cpart-1-1 -s ALCL00000001 -r cp-1
+ -u 0 -o 1
'''
)
@@ -823,32 +921,42 @@
make_option('-n', '--name', action="store", dest='name', type='string',
help='name of vont ani', default=None),
make_option('-d', '--description', action="store", dest='description',
- type='string', help='description of vont ani', default=None),
- make_option('-a', '--admin_state', action="store", dest='enabled', type='string',
- help='admin state of vont ani', default=None),
- make_option('-l', '--trap', action="store", dest='link_up_down_trap_enable',
- type='string', help='link up down trap enable type', default=None),
+ type='string', help='description of vont ani',
+ default=None),
+ make_option('-a', '--admin_state', action="store", dest='enabled',
+ type='string', help='admin state of vont ani',
+ default=None),
+ make_option('-l', '--trap', action="store",
+ dest='link_up_down_trap_enable', type='string',
+ help='link up down trap enable type', default=None),
make_option('-p', '--parent_ref', action='store', dest='parent_ref',
- type='string', help='parent reference of vont ani must be type of channel partition',
+ type='string',
+ help='parent reference of vont ani must be type of \
+ channel partition', default=None),
+ make_option('-s', '--e_ser_num', action='store',
+ dest='expected_serial_number', type='string',
+ help='expected serial number of ONT', default=None),
+ make_option('-i', '--e_reg_id', action='store',
+ dest='expected_registration_id', type='string',
+ help='expected registration id of ONT', default=None),
+ make_option('-r', '--pref_cp', action='store',
+ dest='preferred_chanpair', type='string',
+ help='preferred channel pair must be type of channel pair',
default=None),
- make_option('-s', '--e_ser_num', action='store', dest='expected_serial_number',
- type='string', help='expected serial number of ONT', default=None),
- make_option('-i', '--e_reg_id', action='store', dest='expected_registration_id',
- type='string', help='expected registration id of ONT', default=None),
- make_option('-r', '--pref_cp', action='store', dest='preferred_chanpair',
- type='string', help='preferred channel pair must be type of channel pair',
- default=None),
- make_option('-t', '--prot_cp', action='store', dest='protection_chanpair',
- type='string', help='protection channel pair must be type of channel pair',
- default=None),
- make_option('-u', '--up_cs', action='store', dest='upstream_channel_speed',
- type='int', help='upstream channel speed of traffic', default=None),
+ make_option('-t', '--prot_cp', action='store',
+ dest='protection_chanpair', type='string',
+ help='protection channel pair must be type of channel \
+ pair', default=None),
+ make_option('-u', '--up_cs', action='store',
+ dest='upstream_channel_speed', type='int',
+ help='upstream channel speed of traffic', default=None),
make_option('-o', '--onu_id', action='store', dest='onu_id',
type='int', help='onu id', default=None),
])
def do_vont_ani(self, line, opts):
- """vont ani get, create -flags <attributes>, update -flags <attributes>, delete -n <name>"""
+ """vont ani get, create -flags <attributes>,
+ update -flags <attributes>, delete -n <name>"""
# Ensure that a valid sub-command was provided
if line.strip() not in {"get", "create", "update", "delete"}:
self.poutput(self.colorize('Error: ', 'red') + \
@@ -860,9 +968,11 @@
if line.strip() == "get":
if self.device_id:
- cg, cpart, cp, ct, vont, ont, venet = self.get_interface_based_on_device()
- print_pb_list_as_table("VOnt Anis for device ID = {}:".format(self.device_id),
- vont, {}, self.poutput)
+ cg, cpart, cp, ct, vont, ont, venet = \
+ self.get_interface_based_on_device()
+ print_pb_list_as_table("VOnt Anis for device ID = {}:"
+ .format(self.device_id), vont, {},
+ self.poutput)
else:
interface = stub.GetAllVOntaniConfig(Empty())
print_pb_list_as_table("VOnt Anis:",
@@ -881,18 +991,22 @@
elif opts.enabled == "down":
interface_instance.interface.enabled = False
else:
- self.poutput(self.colorize('Error: ', 'red') + \
- self.colorize(self.colorize('Invalid admin state parameter for vont ani', 'blue'),
- 'bold'))
+ self.poutput(
+ self.colorize('Error: ', 'red') + self.colorize(
+ self.colorize('Invalid admin state parameter for \
+ vont ani', 'blue'), 'bold'))
return
if opts.link_up_down_trap_enable:
types = ["trap_disabled", "trap_enabled"]
try:
assert opts.link_up_down_trap_enable in types, \
- 'Invalid Enum value for VOnt Ani link up down trap enable type \'{}\''\
- .format(opts.link_up_down_trap_enable)
+ 'Invalid Enum value for VOnt Ani link up down trap \
+ enable type \'{}\''.format(
+ opts.link_up_down_trap_enable)
interface_instance.interface.link_up_down_trap_enable = \
- ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.values_by_name[opts.link_up_down_trap_enable.upper()].number
+ ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\
+ values_by_name[opts.link_up_down_trap_enable.upper()].\
+ number
except AssertionError, e:
self.poutput(self.colorize('Error: ', 'red') + \
self.colorize(self.colorize(e.message, 'blue'),
@@ -902,15 +1016,20 @@
if opts.parent_ref:
interface_instance.data.parent_ref = opts.parent_ref
if opts.expected_serial_number:
- interface_instance.data.expected_serial_number = opts.expected_serial_number
+ interface_instance.data.expected_serial_number = \
+ opts.expected_serial_number
if opts.expected_registration_id:
- interface_instance.data.expected_registration_id = opts.expected_registration_id
+ interface_instance.data.expected_registration_id = \
+ opts.expected_registration_id
if opts.preferred_chanpair:
- interface_instance.data.preferred_chanpair = opts.preferred_chanpair
+ interface_instance.data.preferred_chanpair = \
+ opts.preferred_chanpair
if opts.protection_chanpair:
- interface_instance.data.protection_chanpair = opts.protection_chanpair
+ interface_instance.data.protection_chanpair = \
+ opts.protection_chanpair
if opts.upstream_channel_speed:
- interface_instance.data.upstream_channel_speed = opts.upstream_channel_speed
+ interface_instance.data.upstream_channel_speed = \
+ opts.upstream_channel_speed
if opts.onu_id:
interface_instance.data.onu_id = opts.onu_id
@@ -925,16 +1044,17 @@
def help_ont_ani(self):
self.poutput(
'''
-ont_ani [get | create | update | delete] [-n <name>] [-d <description>] [-a <admin state>]
- [-l <link up down trap enable type>] [-u <upstream fec indicator>]
- [-m <management gem port aes indicator>]
+ont_ani [get | create | update | delete] [-n <name>] [-d <description>]
+ [-a <admin state>] [-l <link up down trap enable type>]
+ [-u <upstream fec indicator>] [-m <management gem port aes indicator>]
get: displays existing ont anis
Required flags: None
-create: creates ont ani with the parameters specified with -n, -d, -a, -l, -u and -m.
+create: creates ont ani with the parameters specified with -n, -d, -a, -l, -u
+ and -m.
Required flags: <name>
-update: updates existing ont ani specified with parameter -n by changing its parameter values
- specified with -d, -a, -l, -u and -m.
+update: updates existing ont ani specified with parameter -n by changing its
+ parameter values specified with -d, -a, -l, -u and -m.
Required flags: <name>
delete: deletes ont ani specified with parameter -n.
Required flags: <name>
@@ -956,19 +1076,25 @@
make_option('-n', '--name', action="store", dest='name', type='string',
help='name of ont ani', default=None),
make_option('-d', '--description', action="store", dest='description',
- type='string', help='description of ont ani', default=None),
- make_option('-a', '--admin_state', action="store", dest='enabled', type='string',
- help='admin state of ont ani', default=None),
- make_option('-l', '--trap', action="store", dest='link_up_down_trap_enable',
- type='string', help='link up down trap enable type', default=None),
- make_option('-u', '--up_fec', action='store', dest='upstream_fec_indicator',
- type='string', help='upstream traffic fec indicator', default=None),
- make_option('-m', '--maes', action='store', dest='mgnt_gemport_aes_indicator',
- type='string', help='management gem port aes indicator', default=None),
+ type='string', help='description of ont ani',
+ default=None),
+ make_option('-a', '--admin_state', action="store", dest='enabled',
+ type='string', help='admin state of ont ani',
+ default=None),
+ make_option('-l', '--trap', action="store",
+ dest='link_up_down_trap_enable', type='string',
+ help='link up down trap enable type', default=None),
+ make_option('-u', '--up_fec', action='store',
+ dest='upstream_fec_indicator', type='string',
+ help='upstream traffic fec indicator', default=None),
+ make_option('-m', '--maes', action='store',
+ dest='mgnt_gemport_aes_indicator', type='string',
+ help='management gem port aes indicator', default=None),
])
def do_ont_ani(self, line, opts):
- """ont ani get, create -flags <attributes>, update -flags <attributes>, delete -n <name>"""
+ """ont ani get, create -flags <attributes>,
+ update -flags <attributes>, delete -n <name>"""
# Ensure that a valid sub-command was provided
if line.strip() not in {"get", "create", "update", "delete"}:
self.poutput(self.colorize('Error: ', 'red') + \
@@ -980,9 +1106,10 @@
if line.strip() == "get":
if self.device_id:
- cg, cpart, cp, ct, vont, ont, venet = self.get_interface_based_on_device()
- print_pb_list_as_table("Ont Anis for device ID = {}:".format(self.device_id),
- ont, {}, self.poutput)
+ cg, cpart, cp, ct, vont, ont, venet = \
+ self.get_interface_based_on_device()
+ print_pb_list_as_table("Ont Anis for device ID = {}:".format(
+ self.device_id), ont, {}, self.poutput)
else:
interface = stub.GetAllOntaniConfig(Empty())
print_pb_list_as_table("Ont Anis:",
@@ -1001,18 +1128,22 @@
elif opts.enabled == "down":
interface_instance.interface.enabled = False
else:
- self.poutput(self.colorize('Error: ', 'red') + \
- self.colorize(self.colorize('Invalid admin state parameter for ont ani', 'blue'),
- 'bold'))
+ self.poutput(
+ self.colorize('Error: ', 'red') + self.colorize(
+ self.colorize('Invalid admin state parameter for \
+ ont ani', 'blue'), 'bold'))
return
if opts.link_up_down_trap_enable:
types = ["trap_disabled", "trap_enabled"]
try:
assert opts.link_up_down_trap_enable in types, \
- 'Invalid Enum value for Ont Ani link up down trap enable type \'{}\''\
- .format(opts.link_up_down_trap_enable)
+ 'Invalid Enum value for Ont Ani link up down trap \
+ enable type \'{}\''.format(
+ opts.link_up_down_trap_enable)
interface_instance.interface.link_up_down_trap_enable = \
- ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.values_by_name[opts.link_up_down_trap_enable.upper()].number
+ ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\
+ values_by_name[opts.link_up_down_trap_enable.upper()].\
+ number
except AssertionError, e:
self.poutput(self.colorize('Error: ', 'red') + \
self.colorize(self.colorize(e.message, 'blue'),
@@ -1025,11 +1156,12 @@
elif opts.upstream_fec_indicator == 'false':
interface_instance.data.upstream_fec_indicator = False
else:
- m = 'Invalid boolean value for Ont Ani upstream_fec_indicator \'{}\''\
- .format(opts.upstream_fec_indicator)
- self.poutput(self.colorize('Error: ', 'red') + \
- self.colorize(self.colorize(m, 'blue'),
- 'bold'))
+ m = 'Invalid boolean value for Ont Ani \
+ upstream_fec_indicator \'{}\''.format(
+ opts.upstream_fec_indicator)
+ self.poutput(
+ self.colorize('Error: ', 'red') + self.colorize(
+ self.colorize(m, 'blue'), 'bold'))
return
if opts.mgnt_gemport_aes_indicator:
if opts.mgnt_gemport_aes_indicator == 'true':
@@ -1037,11 +1169,12 @@
elif opts.mgnt_gemport_aes_indicator == 'false':
interface_instance.data.mgnt_gemport_aes_indicator = False
else:
- m = 'Invalid boolean value for Ont Ani mgnt_gemport_aes_indicator \'{}\''\
- .format(opts.mgnt_gemport_aes_indicator)
- self.poutput(self.colorize('Error: ', 'red') + \
- self.colorize(self.colorize(m, 'blue'),
- 'bold'))
+ m = 'Invalid boolean value for Ont Ani \
+ mgnt_gemport_aes_indicator \'{}\''.format(
+ opts.mgnt_gemport_aes_indicator)
+ self.poutput(
+ self.colorize('Error: ', 'red') + self.colorize(
+ self.colorize(m, 'blue'), 'bold'))
return
if line.strip() == "create":
@@ -1055,15 +1188,17 @@
def help_v_enet(self):
self.poutput(
'''
-v_enet [get | create | update | delete] [-n <name>] [-d <description>] [-a <admin state>]
- [-l <link up down trap enable type>] [-r <ont ani reference>]
+v_enet [get | create | update | delete] [-n <name>] [-d <description>]
+ [-a <admin state>] [-l <link up down trap enable type>]
+ [-r <ont ani reference>]
get: displays existing venets
Required flags: None
-create: creates venet with the parameters specified with -n, -d, -a, -l, and -r.
+create: creates venet with the parameters specified with -n, -d, -a, -l,
+ and -r.
Required flags: <name>
-update: updates existing venet specified with parameter -n by changing its parameter values
- specified with -d, -a, -l, -r.
+update: updates existing venet specified with parameter -n by changing its
+ parameter values specified with -d, -a, -l, -r.
Required flags: <name>
delete: deletes venet specified with parameter -n.
Required flags: <name>
@@ -1085,16 +1220,18 @@
help='name of venet', default=None),
make_option('-d', '--description', action="store", dest='description',
type='string', help='description of venet', default=None),
- make_option('-a', '--admin_state', action="store", dest='enabled', type='string',
- help='admin state of venet', default=None),
- make_option('-l', '--trap', action="store", dest='link_up_down_trap_enable',
- type='string', help='link up down trap enable type', default=None),
+ make_option('-a', '--admin_state', action="store", dest='enabled',
+ type='string', help='admin state of venet', default=None),
+ make_option('-l', '--trap', action="store",
+ dest='link_up_down_trap_enable', type='string',
+ help='link up down trap enable type', default=None),
make_option('-r', '--ont_ref', action='store', dest='v_ontani_ref',
type='string', help='ont ani reference', default=None),
])
def do_v_enet(self, line, opts):
- """v_enet get, create -flags <attributes>, update -flags <attributes>, delete -n <name>"""
+ """v_enet get, create -flags <attributes>,
+ update -flags <attributes>, delete -n <name>"""
# Ensure that a valid sub-command was provided
if line.strip() not in {"get", "create", "update", "delete"}:
self.poutput(self.colorize('Error: ', 'red') + \
@@ -1106,9 +1243,11 @@
if line.strip() == "get":
if self.device_id:
- cg, cpart, cp, ct, vont, ont, venet = self.get_interface_based_on_device()
- print_pb_list_as_table("VEnet for device ID = {}:".format(self.device_id),
- venet, {}, self.poutput)
+ cg, cpart, cp, ct, vont, ont, venet = \
+ self.get_interface_based_on_device()
+ print_pb_list_as_table("VEnet for device ID = {}:"
+ .format(self.device_id), venet, {},
+ self.poutput)
else:
interface = stub.GetAllVEnetConfig(Empty())
print_pb_list_as_table("VEnets:",
@@ -1127,18 +1266,22 @@
elif opts.enabled == "down":
interface_instance.interface.enabled = False
else:
- self.poutput(self.colorize('Error: ', 'red') + \
- self.colorize(self.colorize('Invalid admin state parameter for venet', 'blue'),
- 'bold'))
+ self.poutput(
+ self.colorize('Error: ', 'red') + self.colorize(
+ self.colorize('Invalid admin state parameter for \
+ venet', 'blue'), 'bold'))
return
if opts.link_up_down_trap_enable:
types = ["trap_disabled", "trap_enabled"]
try:
assert opts.link_up_down_trap_enable in types, \
- 'Invalid Enum value for Venet link up down trap enable type \'{}\''\
- .format(opts.link_up_down_trap_enable)
+ 'Invalid Enum value for Venet link up down trap \
+ enable type \'{}\''.format(
+ opts.link_up_down_trap_enable)
interface_instance.interface.link_up_down_trap_enable = \
- ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.values_by_name[opts.link_up_down_trap_enable.upper()].number
+ ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\
+ values_by_name[opts.link_up_down_trap_enable.upper()].\
+ number
except AssertionError, e:
self.poutput(self.colorize('Error: ', 'red') + \
self.colorize(self.colorize(e.message, 'blue'),
diff --git a/voltha/core/xpon_agent.py b/voltha/core/xpon_agent.py
index 489ff90..4dd6a87 100644
--- a/voltha/core/xpon_agent.py
+++ b/voltha/core/xpon_agent.py
@@ -19,8 +19,9 @@
from voltha.registry import registry
from voltha.core.config.config_proxy import CallbackType
-from voltha.protos.bbf_fiber_base_pb2 import ChannelgroupConfig, ChannelpartitionConfig, \
- ChannelpairConfig, ChannelterminationConfig, OntaniConfig, VOntaniConfig, VEnetConfig
+from voltha.protos.bbf_fiber_base_pb2 import ChannelgroupConfig, \
+ ChannelpartitionConfig, ChannelpairConfig, ChannelterminationConfig, \
+ OntaniConfig, VOntaniConfig, VEnetConfig
from voltha.protos.device_pb2 import Device
from voltha.protos.common_pb2 import AdminState
@@ -28,23 +29,92 @@
class XponAgent(object):
- interfaces = {ChannelgroupConfig: {'path': '/channel_groups/{}', 'path_keys': ['name'], 'device_id' : ''},
- ChannelpartitionConfig: {'path': '/channel_partitions/{}', 'path_keys': ['name'], 'device_id' : ''},
- ChannelpairConfig: {'path': '/channel_pairs/{}', 'path_keys': ['name'], 'device_id' : ''},
- ChannelterminationConfig: {'path': '/devices/{}/channel_terminations/{}', 'path_keys': ['id', 'name'], 'device_id' : 'id'},
- OntaniConfig: {'path': '/ont_anis/{}', 'path_keys': ['name'], 'device_id' : ''},
- VOntaniConfig: {'path': '/v_ont_anis/{}', 'path_keys': ['name'], 'device_id' : ''},
- VEnetConfig: {'path': '/v_enets/{}', 'path_keys': ['name'], 'device_id' : ''}
+ interfaces = {ChannelgroupConfig: {
+ 'path': '/channel_groups/{}', 'path_keys': ['name'],
+ 'device_id' : ''},
+ ChannelpartitionConfig: {
+ 'path': '/channel_partitions/{}', 'path_keys': ['name'],
+ 'device_id' : ''},
+ ChannelpairConfig: {
+ 'path': '/channel_pairs/{}', 'path_keys': ['name'],
+ 'device_id' : ''},
+ ChannelterminationConfig: {
+ 'path': '/devices/{}/channel_terminations/{}',
+ 'path_keys': ['id', 'name'], 'device_id' : 'id'},
+ OntaniConfig: {
+ 'path': '/ont_anis/{}', 'path_keys': ['name'],
+ 'device_id' : ''},
+ VOntaniConfig: {
+ 'path': '/v_ont_anis/{}', 'path_keys': ['name'],
+ 'device_id' : ''},
+ VEnetConfig: {
+ 'path': '/v_enets/{}', 'path_keys': ['name'],
+ 'device_id' : ''}
}
- interface_stack = {ChannelgroupConfig: {'parent': None, 'parent_path' : None, 'parent_path_keys': [None]},
- ChannelpartitionConfig: {'parent': ChannelgroupConfig, 'parent_path' : '/channel_groups/{}', 'parent_path_keys': ['data.channelgroup_ref']},
- ChannelpairConfig: {'parent': ChannelpartitionConfig, 'parent_path': '/channel_partitions/{}', 'parent_path_keys': ['data.channelpartition_ref']},
- ChannelterminationConfig: {'parent': ChannelpairConfig, 'parent_path': '/channel_pairs/{}', 'parent_path_keys': ['data.channelpair_ref']},
- #VOntaniConfig: {'parent': ChannelpartitionConfig, 'parent_path': '/channel_partitions/{}', 'parent_path_keys': ['data.channelpartition_ref']},
- VOntaniConfig: {'parent': ChannelpairConfig, 'parent_path': '/channel_pairs/{}', 'parent_path_keys': ['data.preferred_chanpair']},
- OntaniConfig: {'parent': VOntaniConfig, 'parent_path': '/v_ont_anis/{}', 'parent_path_keys': ['name']},
- VEnetConfig: {'parent': VOntaniConfig, 'parent_path': '/v_ont_anis/{}', 'parent_path_keys': ['data.v_ontani_ref']}
+ interface_stack = {ChannelgroupConfig: {
+ 'parent': None, 'parent_path': None,
+ 'parent_path_keys': [None],
+ 'child': ChannelpartitionConfig,
+ 'child_path': ['/channel_partitions'],
+ 'olt_link': None, 'olt_link_path': None,
+ 'olt_link_path_keys': [None],
+ 'olt_device_id': 'from_child'},
+ ChannelpartitionConfig: {
+ 'parent': ChannelgroupConfig,
+ 'parent_path': '/channel_groups/{}',
+ 'parent_path_keys': ['data.channelgroup_ref'],
+ 'child': ChannelpairConfig,
+ 'child_path': ['/channel_pairs'],
+ 'olt_link': None, 'olt_link_path': None,
+ 'olt_link_path_keys': [None],
+ 'olt_device_id': 'from_child'},
+ ChannelpairConfig: {
+ 'parent': ChannelpartitionConfig,
+ 'parent_path': '/channel_partitions/{}',
+ 'parent_path_keys':\
+ ['data.channelpartition_ref'],
+ 'child': ChannelterminationConfig,
+ 'child_path':\
+ ['/devices', 'channel_terminations'],
+ 'olt_link': None, 'olt_link_path': None,
+ 'olt_link_path_keys': [None],
+ 'olt_device_id': 'from_child'},
+ ChannelterminationConfig: {
+ 'parent': ChannelpairConfig,
+ 'parent_path': '/channel_pairs/{}',
+ 'parent_path_keys':\
+ ['data.channelpair_ref'],
+ 'child': None, 'child_path': [None],
+ 'olt_link': None, 'olt_link_path': None,
+ 'olt_link_path_keys': [None],
+ 'olt_device_id': 'self'},
+ VOntaniConfig: {
+ 'parent': ChannelpartitionConfig,
+ 'parent_path': '/channel_partitions/{}',
+ 'parent_path_keys': ['data.parent_ref'],
+ 'child': VEnetConfig, 'child_path': ['/v_enets'],
+ 'olt_link': ChannelpairConfig,
+ 'olt_link_path': '/channel_pairs/{}',
+ 'olt_link_path_keys':\
+ ['data.preferred_chanpair'],
+ 'olt_device_id': 'from_link'},
+ OntaniConfig: {
+ 'parent': None, 'parent_path': None,
+ 'parent_path_keys': [None],
+ 'child': None, 'child_path': [None],
+ 'olt_link': VOntaniConfig,
+ 'olt_link_path': '/v_ont_anis/{}',
+ 'olt_link_path_keys': ['name'],
+ 'olt_device_id' : 'from_link'},
+ VEnetConfig: {
+ 'parent': VOntaniConfig,
+ 'parent_path': '/v_ont_anis/{}',
+ 'parent_path_keys': ['data.v_ontani_ref'],
+ 'child': None, 'child_path': [None],
+ 'olt_link': None, 'olt_link_path': None,
+ 'olt_link_path_keys': [None],
+ 'olt_device_id': 'from_parent'}
}
def __init__(self, core):
@@ -57,87 +127,100 @@
device = self.core.get_proxy('/devices/{}'.format(device_id)).get()
assert device.adapter != ''
adapter_agent = registry('adapter_loader').get_agent(device.adapter)
- log.debug('get-device-adapter-agent', device=device, adapter_agent=adapter_agent)
+ log.debug('get-device-adapter-agent', device=device,
+ adapter_agent=adapter_agent)
return device, adapter_agent
def get_interface_path(self, data):
- val = self.interfaces[type(data)]
+ interface = self.interfaces[type(data)]
id_val = {}
count = 0
- for key in val['path_keys']:
+ for key in interface['path_keys']:
id_val[count] = getattr(data, key)
count+=1
- path = val['path'].format(*id_val.values())
+ path = interface['path'].format(*id_val.values())
return path
- def get_device_id(self, data):
- val = self.interfaces[type(data)]
- device_id = None if val['device_id'] is '' else getattr(data, val['device_id'])
+ def _child_predicate(self, data, child):
+ return self.get_parent_data(child).name == data.name
+
+ def _get_child_data_by_path (self, data, path):
+ children = self.core.get_proxy('/').get(path)
+ return next((child for child in children
+ if self._child_predicate(data, child)), None)
+
+ def get_olt_device_id(self, data):
+ if data is None:
+ return None
+ interface = self.interfaces[type(data)]
+ interface_node = self.interface_stack[type(data)]
+ device_id = None if interface['device_id'] is '' \
+ else getattr(data, interface['device_id'])
if device_id is None:
- if(isinstance(data, ChannelpairConfig)):
- device_items = self.core.get_proxy('/').get('/devices')
- for device_item in device_items:
- items = self.core.get_proxy('/').get(
- '/devices/{}/channel_terminations'.format(device_item.id))
- for item in items:
- if item.data.channelpair_ref == data.name:
- return self.get_device_id(item)
- return None
- elif(isinstance(data, ChannelpartitionConfig)):
- items = self.core.get_proxy('/').get('/channel_pairs')
- for item in items:
- if item.data.channelpartition_ref == data.name:
- return self.get_device_id(item)
- return None
- elif(isinstance(data, ChannelgroupConfig)):
- items = self.core.get_proxy('/').get('/channel_partitions')
- for item in items:
- if item.data.channelgroup_ref == data.name:
- return self.get_device_id(item)
- return None
- # Take care of ont ani and v ont ani
- elif(isinstance(data, VOntaniConfig)):
- channel_part_items = self.core.get_proxy('/').get('/channel_partitions')
- channel_pair_items = self.core.get_proxy('/').get('/channel_pairs')
- for channel_part_item in channel_part_items:
- if channel_part_item.name == data.data.parent_ref:
- return self.get_device_id(channel_part_item)
- for channel_pair_item in channel_pair_items:
- if channel_pair_item.name == data.data.preferred_chanpair or \
- channel_pair_item.name == data.data.protection_chanpair:
- return self.get_device_id(channel_pair_item)
- return None
- elif(isinstance(data, OntaniConfig)):
- v_ont_ani_items = self.core.get_proxy('/').get('/v_ont_anis')
- for v_ont_ani_item in v_ont_ani_items:
- if v_ont_ani_item.name == data.name:
- return self.get_device_id(v_ont_ani_item)
- return None
- elif(isinstance(data, VEnetConfig)):
- v_ont_ani_items = self.core.get_proxy('/').get('/v_ont_anis')
- for v_ont_ani_item in v_ont_ani_items:
- if v_ont_ani_item.name == data.data.v_ontani_ref:
- return self.get_device_id(v_ont_ani_item)
- return None
+ if interface_node['olt_device_id'] == 'from_parent':
+ device_id = self.get_olt_device_id(self.get_parent_data(data))
+ elif interface_node['olt_device_id'] == 'from_child':
+ device_id = self.get_olt_device_id(self.get_child_data(data))
+ elif interface_node['olt_device_id'] == 'from_link':
+ device_id = self.get_olt_device_id(self.get_link_data(data))
return device_id
def get_parent_data(self, data):
if data is None:
return None
- val = self.interface_stack[type(data)]
- if val['parent'] is None:
+ interface_node = self.interface_stack[type(data)]
+ if interface_node['parent'] is None:
return None
id_val = {}
count = 0
- for key in val['parent_path_keys']:
+ for key in interface_node['parent_path_keys']:
id_val[count] = self.rgetattr(data, key)
count+=1
- parent_path = val['parent_path'].format(*id_val.values())
+ parent_path = interface_node['parent_path'].format(*id_val.values())
try:
parent_data = self.core.get_proxy('/').get(parent_path)
return parent_data
except ValueError:
- log.info('xpon-agent-warning-interface-cannot-get-parent', data=data)
+ log.info('xpon-agent-warning-interface-cannot-get-parent',
+ data=data)
+ return None
+
+ def get_child_data(self, data):
+ interface_node = self.interface_stack[type(data)]
+ if len(interface_node['child_path']) > 1:
+ top_children = self.core.get_proxy('/').get('{}'.format(
+ interface_node['child_path'][0]))
+ for top_child in top_children:
+ child = self._get_child_data_by_path(data, '{}/{}/{}'.format(
+ interface_node['child_path'][0], top_child.id,
+ interface_node['child_path'][1]))
+ if child is not None:
+ return child
+ else:
+ child = self._get_child_data_by_path(data, '{}'.format(
+ interface_node['child_path'][0]))
+ if child is None:
+ log.info('xpon-agent-warning-interface-cannot-get-child',
+ data=data)
+ return child
+
+ def get_link_data(self, data):
+ interface_node = self.interface_stack[type(data)]
+ if interface_node['olt_link'] is None:
+ return None
+ id_val = {}
+ count = 0
+ for key in interface_node['olt_link_path_keys']:
+ id_val[count] = self.rgetattr(data, key)
+ count+=1
+ olt_link_path = interface_node['olt_link_path'].format(
+ *id_val.values())
+ try:
+ link_data = self.core.get_proxy('/').get(olt_link_path)
+ return link_data
+ except ValueError:
+ log.info('xpon-agent-warning-interface-cannot-get-link-data',
+ data=data)
return None
def rgetattr(self, obj, attr):
@@ -156,10 +239,16 @@
try:
interface_proxy = self.core.get_proxy(path)
if update:
- interface_proxy.register_callback(CallbackType.POST_UPDATE, self.update_interface, device_id)
+ interface_proxy.register_callback(CallbackType.POST_UPDATE,
+ self.update_interface,
+ device_id)
else:
- interface_proxy.register_callback(CallbackType.POST_ADD, self.create_interface, device_id)
- interface_proxy.register_callback(CallbackType.POST_REMOVE, self.remove_interface, device_id)
+ interface_proxy.register_callback(CallbackType.POST_ADD,
+ self.create_interface,
+ device_id)
+ interface_proxy.register_callback(CallbackType.POST_REMOVE,
+ self.remove_interface,
+ device_id)
except:
print "Unexpected error:", sys.exc_info()[0]
@@ -168,36 +257,47 @@
try:
interface_proxy = self.core.get_proxy(path)
if update:
- interface_proxy.unregister_callback(CallbackType.POST_UPDATE, self.update_interface, device_id)
+ interface_proxy.unregister_callback(CallbackType.POST_UPDATE,
+ self.update_interface,
+ device_id)
else:
- interface_proxy.unregister_callback(CallbackType.POST_ADD, self.create_interface, device_id)
- interface_proxy.unregister_callback(CallbackType.POST_REMOVE, self.remove_interface, device_id)
+ interface_proxy.unregister_callback(CallbackType.POST_ADD,
+ self.create_interface,
+ device_id)
+ interface_proxy.unregister_callback(CallbackType.POST_REMOVE,
+ self.remove_interface,
+ device_id)
except:
print "Unexpected error:", sys.exc_info()[0]
def create_interface(self, data, device_id=None):
if device_id is None:
- device_id = self.get_device_id(data)
+ device_id = self.get_olt_device_id(data)
if not self.is_valid_interface(data):
- log.info('xpon-agent-create-interface-invalid-interface-type', type=type(data).__name__)
+ log.info('xpon-agent-create-interface-invalid-interface-type',
+ type=type(data).__name__)
return
- self.register_interface(device_id=device_id, path=self.get_interface_path(data))
+ self.register_interface(device_id=device_id,
+ path=self.get_interface_path(data))
if device_id is not None:
if(isinstance(data, ChannelterminationConfig)):
self.create_channel_termination(data, device_id)
elif(isinstance(data, VOntaniConfig)):
self.create_v_ont_ani(data, device_id)
else:
- log.info('xpon-agent-create-interface:', device_id=device_id, data=data)
- device, adapter_agent = self.get_device_adapter_agent(device_id)
+ log.info('xpon-agent-create-interface:', device_id=device_id,
+ data=data)
+ device, adapter_agent = \
+ self.get_device_adapter_agent(device_id)
adapter_agent.create_interface(device=device, data=data)
def update_interface(self, data, device_id):
if not self.is_valid_interface(data):
- log.info('xpon-agent-update-interface-invalid-interface-type', type=type(data).__name__)
+ log.info('xpon-agent-update-interface-invalid-interface-type',
+ type=type(data).__name__)
return
if device_id is None:
- device_id = self.get_device_id(data)
+ device_id = self.get_olt_device_id(data)
if device_id is not None:
# This can be any interface
device, adapter_agent = self.get_device_adapter_agent(device_id)
@@ -211,12 +311,14 @@
parent_data = self.get_parent_data(parent_data)
for interface in interfaces:
- log.info('xpon-agent-creating-interface', device_id=device_id, data=interface)
- adapter_agent.create_interface(device=device, data=interface)
+ log.info('xpon-agent-creating-interface',
+ device_id=device_id, data=interface)
+ adapter_agent.create_interface(device=device,
+ data=interface)
venet_items = self.core.get_proxy('/').get('/v_enets')
for venet in venet_items:
- if device_id == self.get_device_id(venet):
+ if device_id == self.get_olt_device_id(venet):
ont_interfaces.insert(0, venet)
parent_data = self.get_parent_data(venet)
while not isinstance(parent_data, ChannelpairConfig):
@@ -224,24 +326,30 @@
parent_data = self.get_parent_data(parent_data)
for ont_interface in ont_interfaces:
- log.info('xpon-agent-creating-ont-interface', device_id=device_id, data=ont_interface)
- adapter_agent.create_interface(device=device, data=ont_interface)
+ log.info('xpon-agent-creating-ont-interface',
+ device_id=device_id, data=ont_interface)
+ adapter_agent.create_interface(device=device,
+ data=ont_interface)
- log.info('xpon-agent-updating-interface', device_id=device_id, data=data)
+ log.info('xpon-agent-updating-interface', device_id=device_id,
+ data=data)
adapter_agent.update_interface(device=device, data=data)
def remove_interface(self, data, device_id=None):
if device_id is None:
- device_id = self.get_device_id(data)
+ device_id = self.get_olt_device_id(data)
if not self.is_valid_interface(data):
- log.info('xpon-agent-remove-interface-invalid-interface-type', type=type(data).__name__)
+ log.info('xpon-agent-remove-interface-invalid-interface-type',
+ type=type(data).__name__)
return
- log.info('xpon-agent-remove-interface:', device_id=device_id, data=data)
+ log.info('xpon-agent-remove-interface:', device_id=device_id,
+ data=data)
if device_id is not None:
if(isinstance(data, ChannelterminationConfig)):
self.remove_channel_termination(data, device_id)
else:
- device, adapter_agent = self.get_device_adapter_agent(device_id)
+ device, adapter_agent = \
+ self.get_device_adapter_agent(device_id)
adapter_agent.remove_interface(device=device, data=data)
if isinstance(data, VOntaniConfig):
self.delete_onu_device(device_id=device_id, v_ont_ani=data)
@@ -251,22 +359,25 @@
channel_pair = self.get_parent_data(data)
channel_part = self.get_parent_data(channel_pair)
channel_group = self.get_parent_data(channel_part)
-
if channel_group:
- log.info('xpon-agent-creating-channel-group', device_id=device_id, data=channel_group)
+ log.info('xpon-agent-creating-channel-group', device_id=device_id,
+ data=channel_group)
adapter_agent.create_interface(device=device, data=channel_group)
if channel_part:
- log.info('xpon-agent-creating-channel-partition:', device_id=device_id, data=channel_part)
+ log.info('xpon-agent-creating-channel-partition:',
+ device_id=device_id, data=channel_part)
adapter_agent.create_interface(device=device, data=channel_part)
if channel_pair:
- log.info('xpon-agent-creating-channel-pair:', device_id=device_id, data=channel_pair)
+ log.info('xpon-agent-creating-channel-pair:', device_id=device_id,
+ data=channel_pair)
adapter_agent.create_interface(device=device, data=channel_pair)
- log.info('xpon-agent-creating-channel-termination:', device_id=device_id, data=data)
+ log.info('xpon-agent-creating-channel-termination:',
+ device_id=device_id, data=data)
adapter_agent.create_interface(device=device, data=data)
# Take care of ont ani and v ont ani
vont_items = self.core.get_proxy('/').get('/v_ont_anis')
for vont in vont_items:
- vont_id = self.get_device_id(vont)
+ vont_id = self.get_olt_device_id(vont)
if device_id == vont_id:
self.create_v_ont_ani(vont, device_id)
@@ -275,72 +386,89 @@
self.create_onu_device(device_id=device_id, v_ont_ani=data)
device, adapter_agent = self.get_device_adapter_agent(device_id)
venets = self.core.get_proxy('/').get('/v_enets')
- log.info('xpon-agent-creating-vont-ani:', device_id=device_id, data=data)
+ log.info('xpon-agent-creating-vont-ani:', device_id=device_id,
+ data=data)
adapter_agent.create_interface(device=device, data=data)
-
try:
- ont_ani = self.core.get_proxy('/').get('/ont_anis/{}'.format(data.name))
- log.info('xpon-agent-create-v-ont-ani-creating-ont-ani:', device_id=device_id, data=ont_ani)
+ ont_ani = self.core.get_proxy('/').get('/ont_anis/{}'
+ .format(data.name))
+ log.info('xpon-agent-create-v-ont-ani-creating-ont-ani:',
+ device_id=device_id, data=ont_ani)
adapter_agent.create_interface(device=device, data=ont_ani)
except KeyError:
- log.info('xpon-agent-create-v-ont-ani-there-is-no-ont-ani-to-create')
-
+ log.info(
+ 'xpon-agent-create-v-ont-ani-there-is-no-ont-ani-to-create')
for venet in venets:
if venet.data.v_ontani_ref == data.name:
- log.info('xpon-agent-create-v-ont-ani-creating-v-enet:', device_id=device_id, data=venet)
+ log.info('xpon-agent-create-v-ont-ani-creating-v-enet:',
+ device_id=device_id, data=venet)
adapter_agent.create_interface(device=device, data=venet)
def remove_channel_termination(self, data, device_id):
device, adapter_agent = self.get_device_adapter_agent(device_id)
- log.info('xpon-agent-removing-channel-termination:', device_id=device_id, data=data)
+ log.info('xpon-agent-removing-channel-termination:',
+ device_id=device_id, data=data)
adapter_agent.remove_interface(device=device, data=data)
if data.data.channelpair_ref:
channel_pair = self.get_parent_data(data)
- log.info('xpon-agent-removing-channel-pair:', device_id=device_id, data=channel_pair)
+ log.info('xpon-agent-removing-channel-pair:', device_id=device_id,
+ data=channel_pair)
adapter_agent.remove_interface(device=device, data=channel_pair)
# Remove vontani and ontani if it has reference to cpair
items = self.core.get_proxy('/').get('/v_ont_anis')
for item in items:
if (item.data.preferred_chanpair == channel_pair.name or \
item.data.protection_chanpair == channel_pair.name):
- log.info('xpon-agent-removing-vont-ani:', device_id=device_id, data=item)
+ log.info('xpon-agent-removing-vont-ani:',
+ device_id=device_id, data=item)
adapter_agent.remove_interface(device=device, data=item)
self.delete_onu_device(device_id=device_id, v_ont_ani=item)
venets_items = self.core.get_proxy('/').get('/v_enets')
for venet in venets_items:
if item.name == venet.data.v_ontani_ref:
- log.info('xpon-agent-removing-v-enet:', device_id=device_id, data=venet)
- adapter_agent.remove_interface(device=device, data=venet)
+ log.info('xpon-agent-removing-v-enet:',
+ device_id=device_id, data=venet)
+ adapter_agent.remove_interface(device=device,
+ data=venet)
ontani_items = self.core.get_proxy('/').get('/ont_anis')
for ontani_item in ontani_items:
if ontani_item.name == item.name:
- log.info('xpon-agent-removing-ont-ani:', device_id=device_id, data=ontani_item)
- adapter_agent.remove_interface(device=device, data=ontani_item)
+ log.info('xpon-agent-removing-ont-ani:',
+ device_id=device_id, data=ontani_item)
+ adapter_agent.remove_interface(device=device,
+ data=ontani_item)
# Remove cpart if exists
if channel_pair.data.channelpartition_ref:
channel_part = self.get_parent_data(channel_pair)
- log.info('xpon-agent-removing-channel-partition:', device_id=device_id, data=channel_part)
- adapter_agent.remove_interface(device=device, data=channel_part)
+ log.info('xpon-agent-removing-channel-partition:',
+ device_id=device_id, data=channel_part)
+ adapter_agent.remove_interface(device=device,
+ data=channel_part)
if channel_part.data.channelgroup_ref:
channel_group = self.get_parent_data(channel_part)
- log.info('xpon-agent-removing-channel-group:', device_id=device_id, data=channel_group)
- adapter_agent.remove_interface(device=device, data=channel_group)
+ log.info('xpon-agent-removing-channel-group:',
+ device_id=device_id, data=channel_group)
+ adapter_agent.remove_interface(device=device,
+ data=channel_group)
def replay_interface(self, device_id):
self.inReplay = True
- ct_items = self.core.get_proxy('/').get('/devices/{}/channel_terminations'.format(device_id))
+ ct_items = self.core.get_proxy('/').get(
+ '/devices/{}/channel_terminations'.format(device_id))
for ct in ct_items:
self.create_interface(data=ct, device_id=device_id)
self.inReplay = False
def get_port_num(self, device_id, label):
log.info('get-port-num:', label=label, device_id=device_id)
- ports = self.core.get_proxy('/').get('/devices/{}/ports'.format(device_id))
- log.info('get-port-num:', label=label, device_id=device_id, ports=ports)
+ ports = self.core.get_proxy('/').get('/devices/{}/ports'.
+ format(device_id))
+ log.info('get-port-num:', label=label, device_id=device_id,
+ ports=ports)
for port in ports:
if port.label == label:
return port.port_no
@@ -349,23 +477,27 @@
def create_onu_device(self, device_id, v_ont_ani):
log.info('create-onu-device', v_ont_ani=v_ont_ani, device=device_id)
device, adapter_agent = self.get_device_adapter_agent(device_id)
- parent_chnl_pair_id = self.get_port_num(device.id, v_ont_ani.data.preferred_chanpair)
+ parent_chnl_pair_id = self.get_port_num(
+ device.id, v_ont_ani.data.preferred_chanpair)
log.info('create-onu-device:', parent_chnl_pair_id=parent_chnl_pair_id)
onu_type = v_ont_ani.data.expected_serial_number[:4]
- proxy_address = Device.ProxyAddress(device_id=device.id, channel_id=parent_chnl_pair_id,
- onu_id=v_ont_ani.data.onu_id, onu_session_id=v_ont_ani.data.onu_id)
- adapter_agent.child_device_detected(parent_device_id=device.id, parent_port_no=parent_chnl_pair_id,
- child_device_type=onu_type,
- proxy_address=proxy_address,
- root=True, serial_number=v_ont_ani.data.expected_serial_number,
- admin_state=AdminState.ENABLED if v_ont_ani.interface.enabled else AdminState.DISABLED
- )
+ proxy_address = Device.ProxyAddress(
+ device_id=device.id, channel_id=parent_chnl_pair_id,
+ onu_id=v_ont_ani.data.onu_id, onu_session_id=v_ont_ani.data.onu_id)
+ adapter_agent.child_device_detected(
+ parent_device_id=device.id, parent_port_no=parent_chnl_pair_id,
+ child_device_type=onu_type, proxy_address=proxy_address, root=True,
+ serial_number=v_ont_ani.data.expected_serial_number,
+ admin_state=AdminState.ENABLED if v_ont_ani.interface.enabled else
+ AdminState.DISABLED)
return
def delete_onu_device(self, device_id, v_ont_ani):
log.info('delete-onu-device', v_ont_ani=v_ont_ani, device=device_id)
device, adapter_agent = self.get_device_adapter_agent(device_id)
- onu_device = adapter_agent.get_child_device(parent_device_id=device_id, serial_number=v_ont_ani.data.expected_serial_number)
+ onu_device = adapter_agent.get_child_device(
+ parent_device_id=device_id,
+ serial_number=v_ont_ani.data.expected_serial_number)
if onu_device is not None:
adapter_agent.delete_child_device(device_id, onu_device.id)
return