Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright 2016 the original author or authors. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | |
| 18 | """ |
| 19 | XPon level CLI commands |
| 20 | """ |
| 21 | from optparse import make_option |
| 22 | from cmd2 import Cmd, options |
| 23 | from simplejson import dumps |
| 24 | |
| 25 | from google.protobuf.empty_pb2 import Empty |
| 26 | from cli.table import print_pb_as_table, print_pb_list_as_table |
| 27 | from cli.utils import print_flows, pb2dict |
| 28 | from voltha.protos import third_party |
| 29 | from voltha.protos.bbf_fiber_base_pb2 import \ |
| 30 | AllChannelgroupConfig, ChannelgroupConfig, \ |
| 31 | AllChannelpairConfig, ChannelpairConfig, \ |
| 32 | AllChannelpartitionConfig, ChannelpartitionConfig, \ |
| 33 | AllChannelterminationConfig, ChannelterminationConfig, \ |
| 34 | AllOntaniConfig, OntaniConfig, AllVOntaniConfig , \ |
| 35 | VOntaniConfig, AllVEnetConfig , VEnetConfig |
| 36 | |
| 37 | _ = third_party |
| 38 | from voltha.protos import voltha_pb2, bbf_fiber_types_pb2, ietf_interfaces_pb2 |
| 39 | import sys |
| 40 | from google.protobuf.json_format import MessageToDict |
| 41 | |
| 42 | # Since proto3 won't send fields that are set to 0/false/"" any object that |
| 43 | # might have those values set in them needs to be replicated here such that the |
| 44 | # fields can be adequately |
| 45 | |
| 46 | class XponCli(Cmd): |
| 47 | |
| 48 | def __init__(self, get_channel, device_id): |
| 49 | Cmd.__init__(self) |
| 50 | self.get_channel = get_channel |
| 51 | self.device_id = device_id |
| 52 | self.prompt = '(' + self.colorize( |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 53 | self.colorize('voltha-xpon {}'.format(device_id), 'green'), |
| 54 | 'bold') + ') ' |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 55 | |
| 56 | def cmdloop(self): |
| 57 | self._cmdloop() |
| 58 | |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 59 | def get_ref_interfaces(self, all_interfaces, ref_interfaces): |
| 60 | interface_list = [] |
| 61 | if not all_interfaces: |
| 62 | return interface_list |
| 63 | if isinstance(all_interfaces[0], (ChannelgroupConfig, |
| 64 | ChannelpartitionConfig, |
| 65 | ChannelpairConfig, OntaniConfig)): |
| 66 | for interface in all_interfaces: |
| 67 | if interface.name in ref_interfaces: |
| 68 | interface_list.append(interface) |
| 69 | elif isinstance(all_interfaces[0], VOntaniConfig): |
| 70 | for interface in all_interfaces: |
| 71 | if interface.data.parent_ref in ref_interfaces: |
| 72 | interface_list.append(interface) |
| 73 | elif isinstance(all_interfaces[0], VEnetConfig): |
| 74 | for interface in all_interfaces: |
| 75 | if interface.data.v_ontani_ref in ref_interfaces: |
| 76 | interface_list.append(interface) |
| 77 | return interface_list |
| 78 | |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 79 | def get_interface_based_on_device(self): |
| 80 | stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel()) |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 81 | channel_terminations = stub.GetAllChannelterminationConfig( |
| 82 | voltha_pb2.ID(id=self.device_id)).channeltermination_config |
| 83 | channel_pairs = self.get_ref_interfaces( |
| 84 | stub.GetAllChannelpairConfig(Empty()).channelpair_config, |
| 85 | dict((dt.data.channelpair_ref, dt) for dt in channel_terminations)) |
| 86 | channel_partitions = self.get_ref_interfaces( |
| 87 | stub.GetAllChannelpartitionConfig(Empty()).channelpartition_config, |
| 88 | dict((dt.data.channelpartition_ref, dt) for dt in channel_pairs)) |
| 89 | channel_groups = self.get_ref_interfaces( |
| 90 | stub.GetAllChannelgroupConfig(Empty()).channelgroup_config, |
| 91 | dict((dt.data.channelgroup_ref, dt) for dt in channel_partitions)) |
| 92 | vont_anis = self.get_ref_interfaces( |
| 93 | stub.GetAllVOntaniConfig(Empty()).v_ontani_config, |
| 94 | dict((dt.name, dt) for dt in channel_partitions)) |
| 95 | ont_anis = self.get_ref_interfaces( |
| 96 | stub.GetAllOntaniConfig(Empty()).ontani_config, |
| 97 | dict((dt.name, dt) for dt in vont_anis)) |
| 98 | venets = self.get_ref_interfaces( |
| 99 | stub.GetAllVEnetConfig(Empty()).v_enet_config, |
| 100 | dict((dt.name, dt) for dt in vont_anis)) |
| 101 | return channel_groups, channel_partitions, channel_pairs,\ |
| 102 | channel_terminations, vont_anis, ont_anis, venets |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 103 | |
| 104 | do_exit = Cmd.do_quit |
| 105 | |
| 106 | def do_quit(self, line): |
| 107 | return self._STOP_AND_EXIT |
| 108 | |
| 109 | def do_show(self, line): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 110 | """Show detailed information of each interface based on device ID |
| 111 | or all interfaces""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 112 | stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel()) |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 113 | device_id = self.device_id |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 114 | if line.strip(): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 115 | device_id = line.strip() |
| 116 | if device_id: |
| 117 | cg, cpart, cp, ct, vont, ont, venet = \ |
| 118 | self.get_interface_based_on_device() |
| 119 | print_pb_list_as_table("Channel Groups for device ID = {}:" |
| 120 | .format(device_id), cg, {}, self.poutput) |
| 121 | print_pb_list_as_table("Channel Partitions for device ID = {}:" |
| 122 | .format(device_id),cpart, {}, self.poutput) |
| 123 | print_pb_list_as_table("Channel Pairs: for device ID = {}:" |
| 124 | .format(device_id), cp, {}, self.poutput) |
| 125 | print_pb_list_as_table("Channel Terminations for device ID = {}:" |
| 126 | .format(device_id), ct, {}, self.poutput) |
| 127 | print_pb_list_as_table("VOnt Anis for device ID = {}:" |
| 128 | .format(device_id), vont, {}, self.poutput) |
| 129 | print_pb_list_as_table("Ont Anis for device ID = {}:" |
| 130 | .format(device_id), ont, {}, self.poutput) |
| 131 | print_pb_list_as_table("VEnets for device ID = {}:" |
| 132 | .format(device_id), venet, {}, self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 133 | else: |
| 134 | interface = stub.GetAllChannelgroupConfig(Empty()) |
| 135 | print_pb_list_as_table("Channel Groups:", |
| 136 | interface.channelgroup_config, |
| 137 | {}, self.poutput) |
| 138 | interface = stub.GetAllChannelpartitionConfig(Empty()) |
| 139 | print_pb_list_as_table("Channel Partitions:", |
| 140 | interface.channelpartition_config, |
| 141 | {}, self.poutput) |
| 142 | interface = stub.GetAllChannelpairConfig(Empty()) |
| 143 | print_pb_list_as_table("Channel Pairs:", |
| 144 | interface.channelpair_config, |
| 145 | {}, self.poutput) |
| 146 | devices = stub.ListDevices(Empty()) |
| 147 | for d in devices.items: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 148 | interface = stub.GetAllChannelterminationConfig( |
| 149 | voltha_pb2.ID(id=d.id)) |
| 150 | print_pb_list_as_table( |
| 151 | "Channel Terminations for device ID = {}:" |
| 152 | .format(d.id), interface.channeltermination_config, |
| 153 | {}, self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 154 | interface = stub.GetAllVOntaniConfig(Empty()) |
| 155 | print_pb_list_as_table("VOnt Anis:", |
| 156 | interface.v_ontani_config, |
| 157 | {}, self.poutput) |
| 158 | interface = stub.GetAllOntaniConfig(Empty()) |
| 159 | print_pb_list_as_table("Ont Anis:", |
| 160 | interface.ontani_config, |
| 161 | {}, self.poutput) |
| 162 | interface = stub.GetAllVEnetConfig(Empty()) |
| 163 | print_pb_list_as_table("VEnets:", |
| 164 | interface.v_enet_config, |
| 165 | {}, self.poutput) |
| 166 | |
| 167 | def help_channel_group(self): |
| 168 | self.poutput( |
| 169 | ''' |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 170 | channel_group [get | create | update | delete] [-n <name>] [-d <description>] |
| 171 | [-a <admin state>] [-l <link up down trap enable type>] |
| 172 | [-p <polling period>] [-s <system id>] [-r <raman mitigation>] |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 173 | |
| 174 | get: displays existing channel groups |
| 175 | Required flags: None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 176 | create: creates channel group with the parameters specified with -n, -d, -a, |
| 177 | -l, -p, -s and -r. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 178 | Required flags: <name> |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 179 | update: updates existing channel group specified with parameter -n by changing |
| 180 | its parameter values specified with -d, -a, -l, -p, -s and -r. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 181 | Required flags: <name> |
| 182 | delete: deletes channel group specified with parameter -n. |
| 183 | Required flags: <name> |
| 184 | |
| 185 | -n: <string> name of channel group. |
| 186 | -d: <string> description of channel group. |
| 187 | -a: <string> admin state of channel group. |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 188 | -l: <enum> link up down trap enable type. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 189 | -p: <int> polling period for channel group. |
| 190 | -s: <string> system id for channel group. |
| 191 | -r: <enum> raman mitigation for channel group. |
| 192 | |
| 193 | Example: |
| 194 | |
| 195 | channel_group create -n cg-1 -a up -p 100 -s 000000 -r raman_none |
| 196 | ''' |
| 197 | ) |
| 198 | |
| 199 | @options([ |
| 200 | make_option('-n', '--name', action="store", dest='name', type='string', |
| 201 | help='name of channel group', default=None), |
| 202 | make_option('-d', '--description', action="store", dest='description', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 203 | type='string', help='description of channel group', |
| 204 | default=None), |
| 205 | make_option('-a', '--admin_state', action="store", dest='enabled', |
| 206 | type='string', help='admin state of channel group', |
| 207 | default=None), |
| 208 | make_option('-l', '--trap', action="store", |
| 209 | dest='link_up_down_trap_enable', type='string', |
| 210 | help='link up down trap enable type', default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 211 | make_option('-p', '--pp', action='store', dest='polling_period', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 212 | type='int', help='polling period of channel group', |
| 213 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 214 | make_option('-s', '--sid', action='store', dest='system_id', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 215 | type='string', help='system id of channel group', |
| 216 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 217 | make_option('-r', '--rm', action='store', dest='raman_mitigation', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 218 | type='string', help='raman mitigation of channel group', |
| 219 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 220 | ]) |
| 221 | |
| 222 | def do_channel_group(self, line, opts): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 223 | """channel group get, create -flags <attributes>, |
| 224 | update -flags <attributes>, delete -n <name>""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 225 | # Ensure that a valid sub-command was provided |
| 226 | if line.strip() not in {"get", "create", "update", "delete"}: |
| 227 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 228 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 229 | 'bold') + ' is not recognized') |
| 230 | return |
| 231 | |
| 232 | stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel()) |
| 233 | |
| 234 | if line.strip() == "get": |
| 235 | if self.device_id: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 236 | cg, cpart, cp, ct, vont, ont, venet = \ |
| 237 | self.get_interface_based_on_device() |
| 238 | print_pb_list_as_table("Channel Groups for device ID = {}:" |
| 239 | .format(self.device_id), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 240 | cg, {}, self.poutput) |
| 241 | else: |
| 242 | interface = stub.GetAllChannelgroupConfig(Empty()) |
| 243 | print_pb_list_as_table("Channel Groups:", |
| 244 | interface.channelgroup_config, |
| 245 | {}, self.poutput) |
| 246 | return |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 247 | interface_instance = ChannelgroupConfig(name = opts.name) |
| 248 | interface_instance.interface.name = opts.name |
| 249 | if opts.description: |
| 250 | interface_instance.interface.description = opts.description |
| 251 | interface_instance.interface.type = "channelgroup" |
| 252 | if opts.enabled: |
| 253 | if opts.enabled == "up": |
| 254 | interface_instance.interface.enabled = True |
| 255 | elif opts.enabled == "down": |
| 256 | interface_instance.interface.enabled = False |
| 257 | else: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 258 | self.poutput( |
| 259 | self.colorize('Error: ', 'red') + self.colorize( |
| 260 | self.colorize( |
| 261 | 'Invalid admin state parameter for channel group', |
| 262 | 'blue'), 'bold')) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 263 | return |
| 264 | if opts.link_up_down_trap_enable: |
| 265 | types = ["trap_disabled", "trap_enabled"] |
| 266 | try: |
| 267 | assert opts.link_up_down_trap_enable in types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 268 | 'Invalid Enum value for Channel Group link up down trap \ |
| 269 | enable type \'{}\''.format(opts.link_up_down_trap_enable) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 270 | interface_instance.interface.link_up_down_trap_enable = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 271 | ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\ |
| 272 | values_by_name[opts.link_up_down_trap_enable.upper()]\ |
| 273 | .number |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 274 | except AssertionError, e: |
| 275 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 276 | self.colorize(self.colorize(e.message, 'blue'), |
| 277 | 'bold')) |
| 278 | return |
| 279 | |
| 280 | if opts.polling_period: |
| 281 | interface_instance.data.polling_period = opts.polling_period |
| 282 | if opts.raman_mitigation: |
| 283 | raman_mitigations = ["raman_none", "raman_miller", "raman_8b10b"] |
| 284 | try: |
| 285 | assert opts.raman_mitigation in raman_mitigations, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 286 | 'Invalid Enum value for Channel Group raman mitigation\ |
| 287 | \'{}\''.format(opts.raman_mitigation) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 288 | interface_instance.data.raman_mitigation = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 289 | bbf_fiber_types_pb2._RAMANMITIGATIONTYPE.\ |
| 290 | values_by_name[opts.raman_mitigation.upper()].number |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 291 | except AssertionError, e: |
| 292 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 293 | self.colorize(self.colorize(e.message, 'blue'), |
| 294 | 'bold')) |
| 295 | return |
| 296 | if opts.system_id: |
| 297 | interface_instance.data.system_id = opts.system_id |
| 298 | |
| 299 | if line.strip() == "create": |
| 300 | stub.CreateChannelgroup(interface_instance) |
| 301 | elif line.strip() == "update": |
| 302 | stub.UpdateChannelgroup(interface_instance) |
| 303 | elif line.strip() == "delete": |
| 304 | stub.DeleteChannelgroup(interface_instance) |
| 305 | return |
| 306 | |
| 307 | def help_channel_partition(self): |
| 308 | self.poutput( |
| 309 | ''' |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 310 | channel_partition [get | create | update | delete] [-n <name>] |
| 311 | [-d <description>] [-a <admin state>] |
| 312 | [-l <link up down trap enable type>] |
| 313 | [-r <differential fiber distance>] |
| 314 | [-o <closest ont distance>] [-f <fec downstream>] |
| 315 | [-m <multicast aes indicator>] [-u <authentication method>] |
| 316 | [-c <channel group reference>] |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 317 | |
| 318 | get: displays existing channel partitions |
| 319 | Required flags: None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 320 | create: creates channel partition with the parameters specified with -n, -d, |
| 321 | -a, -l, -r, -o, -f, -m, -u and -c. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 322 | Required flags: <name>, <channel group reference> |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 323 | update: updates existing channel partition specified with parameter -n by |
| 324 | changing its parameter values specified with -d, -a, -l, -r, -o, -f, |
| 325 | -m, -u and -c. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 326 | Required flags: <name> |
| 327 | delete: deletes channel group specified with parameter -n. |
| 328 | Required flags: <name> |
| 329 | |
| 330 | -n: <string> name of channel partition. |
| 331 | -d: <string> description of channel partition. |
| 332 | -a: <string> admin state of channel partition. |
| 333 | -l: <enum> link up down trap enable type. |
| 334 | -r: <int> differential fiber distance. |
| 335 | -o: <int> closest ont distance. |
| 336 | -f: <bool> forward and error correction downstream. |
| 337 | -m: <bool> multicast aes indicator of channel partition. |
| 338 | -u: <enum> authentication method. |
| 339 | -c: <string> channel group reference for this channel partition. |
| 340 | |
| 341 | Example: |
| 342 | |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 343 | channel_partition create -n cpart-1-1 -a up -r 20 -o 0 -f false -m false |
| 344 | -u serial_number -c cg-1 |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 345 | ''' |
| 346 | ) |
| 347 | |
| 348 | @options([ |
| 349 | make_option('-n', '--name', action="store", dest='name', type='string', |
| 350 | help='name of channel partition', default=None), |
| 351 | make_option('-d', '--description', action="store", dest='description', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 352 | type='string', help='description of channel partition', |
| 353 | default=None), |
| 354 | make_option('-a', '--admin_state', action="store", dest='enabled', |
| 355 | type='string', help='admin state of channel partition', |
| 356 | default=None), |
| 357 | make_option('-l', '--trap', action="store", |
| 358 | dest='link_up_down_trap_enable', type='string', |
| 359 | help='link up down trap enable type', default=None), |
| 360 | make_option('-r', '--diff_fib_dist', action='store', |
| 361 | dest='differential_fiber_distance', type='int', |
| 362 | help='differential fiber distance', default=None), |
| 363 | make_option('-o', '--ont_dist', action='store', |
| 364 | dest='closest_ont_distance', type='int', |
| 365 | help='closest ont distance', default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 366 | make_option('-f', '--fec_ds', action='store', dest='fec_downstream', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 367 | type='string', |
| 368 | help='forward and error correction downstream', |
| 369 | default=None), |
| 370 | make_option('-m', '--mc_aes', action='store', |
| 371 | dest='multicast_aes_indicator', type='string', |
| 372 | help='multicast aes indicator of channel partition', |
| 373 | default=None), |
| 374 | make_option('-u', '--auth', action='store', |
| 375 | dest='authentication_method', type='string', |
| 376 | help='authentication method', default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 377 | make_option('-c', '--cg_ref', action='store', dest='channelgroup_ref', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 378 | type='string', |
| 379 | help='channel group reference for this channel partition', |
| 380 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 381 | ]) |
| 382 | |
| 383 | def do_channel_partition(self, line, opts): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 384 | """channel partition get, create -flags <attributes>, |
| 385 | update -flags <attributes>, delete -n <name>""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 386 | # Ensure that a valid sub-command was provided |
| 387 | if line.strip() not in {"get", "create", "update", "delete"}: |
| 388 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 389 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 390 | 'bold') + ' is not recognized') |
| 391 | return |
| 392 | |
| 393 | stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel()) |
| 394 | |
| 395 | if line.strip() == "get": |
| 396 | if self.device_id: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 397 | cg, cpart, cp, ct, vont, ont, venet = \ |
| 398 | self.get_interface_based_on_device() |
| 399 | print_pb_list_as_table("Channel Partitions for device ID = {}:" |
| 400 | .format(self.device_id), cpart, {}, |
| 401 | self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 402 | else: |
| 403 | interface = stub.GetAllChannelpartitionConfig(Empty()) |
| 404 | print_pb_list_as_table("Channel Partitions:", |
| 405 | interface.channelpartition_config, |
| 406 | {}, self.poutput) |
| 407 | return |
| 408 | |
| 409 | interface_instance = ChannelpartitionConfig(name = opts.name) |
| 410 | interface_instance.interface.name = opts.name |
| 411 | if opts.description: |
| 412 | interface_instance.interface.description = opts.description |
| 413 | interface_instance.interface.type = "channelpartition" |
| 414 | if opts.enabled: |
| 415 | if opts.enabled == "up": |
| 416 | interface_instance.interface.enabled = True |
| 417 | elif opts.enabled == "down": |
| 418 | interface_instance.interface.enabled = False |
| 419 | else: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 420 | self.poutput( |
| 421 | self.colorize('Error: ', 'red') + self.colorize( |
| 422 | self.colorize('Invalid admin state parameter for \ |
| 423 | channel partition', 'blue'), 'bold')) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 424 | return |
| 425 | if opts.link_up_down_trap_enable: |
| 426 | types = ["trap_disabled", "trap_enabled"] |
| 427 | try: |
| 428 | assert opts.link_up_down_trap_enable in types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 429 | 'Invalid Enum value for Channel Partition link up \ |
| 430 | down trap enable type \'{}\''\ |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 431 | .format(opts.link_up_down_trap_enable) |
| 432 | interface_instance.interface.link_up_down_trap_enable = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 433 | ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\ |
| 434 | values_by_name[opts.link_up_down_trap_enable.upper()].\ |
| 435 | number |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 436 | except AssertionError, e: |
| 437 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 438 | self.colorize(self.colorize(e.message, 'blue'), |
| 439 | 'bold')) |
| 440 | return |
| 441 | |
| 442 | if opts.differential_fiber_distance: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 443 | interface_instance.data.differential_fiber_distance = \ |
| 444 | opts.differential_fiber_distance |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 445 | if opts.closest_ont_distance: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 446 | interface_instance.data.closest_ont_distance = \ |
| 447 | opts.closest_ont_distance |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 448 | if opts.fec_downstream: |
| 449 | if opts.fec_downstream == 'true': |
| 450 | interface_instance.data.fec_downstream = True |
| 451 | elif opts.fec_downstream == 'false': |
| 452 | interface_instance.data.fec_downstream = False |
| 453 | else: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 454 | m = 'Invalid boolean value for Channel Partition \ |
| 455 | fec_downstream \'{}\''.format(opts.fec_downstream) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 456 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 457 | self.colorize(self.colorize(m, 'blue'), |
| 458 | 'bold')) |
| 459 | return |
| 460 | if opts.multicast_aes_indicator: |
| 461 | if opts.multicast_aes_indicator == 'true': |
| 462 | interface_instance.data.multicast_aes_indicator = True |
| 463 | elif opts.multicast_aes_indicator == 'false': |
| 464 | interface_instance.data.multicast_aes_indicator = False |
| 465 | else: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 466 | m = 'Invalid boolean value for Channel Partition \ |
| 467 | multicast_aes_indicator \'{}\''.format( |
| 468 | opts.multicast_aes_indicator) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 469 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 470 | self.colorize(self.colorize(m, 'blue'), |
| 471 | 'bold')) |
| 472 | return |
| 473 | if opts.authentication_method: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 474 | auth_method_types = \ |
| 475 | ["serial_number", "loid", "registration_id", "omci", "dot1x"] |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 476 | try: |
| 477 | assert opts.authentication_method in auth_method_types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 478 | 'Invalid Enum value for Channel Partition \ |
| 479 | authentication method \'{}\''.format( |
| 480 | opts.authentication_method) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 481 | interface_instance.data.authentication_method = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 482 | bbf_fiber_types_pb2._AUTHMETHODTYPE.\ |
| 483 | values_by_name[opts.authentication_method.upper()].number |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 484 | except AssertionError, e: |
| 485 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 486 | self.colorize(self.colorize(e.message, 'blue'), |
| 487 | 'bold')) |
| 488 | return |
| 489 | if opts.channelgroup_ref: |
| 490 | interface_instance.data.channelgroup_ref = opts.channelgroup_ref |
| 491 | |
| 492 | if line.strip() == "create": |
| 493 | stub.CreateChannelpartition(interface_instance) |
| 494 | elif line.strip() == "update": |
| 495 | stub.UpdateChannelpartition(interface_instance) |
| 496 | elif line.strip() == "delete": |
| 497 | stub.DeleteChannelpartition(interface_instance) |
| 498 | return |
| 499 | |
| 500 | def help_channel_pair(self): |
| 501 | self.poutput( |
| 502 | ''' |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 503 | channel_pair [get | create | update | delete] [-n <name>] [-d <description>] |
| 504 | [-a <admin state>] [-l <link up down trap enable type>] |
| 505 | [-r <channel pair line rate>] [-t <channel pair type>] |
| 506 | [-g <channel group reference>] [-i <gpon pon id interval>] |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 507 | [-p <channel partition reference>] [-o <gpon pon id odn class>] |
| 508 | |
| 509 | get: displays existing channel pairs |
| 510 | Required flags: None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 511 | create: creates channel pair with the parameters specified with -n, -d, -a, |
| 512 | -l, -r, -t, -g, -i, -p and -o. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 513 | Required flags: <name>, <channel pair type> |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 514 | update: updates existing channel pair specified with parameter -n by changing |
| 515 | its parameter values specified with -d, -a, -l, -r, -t, -g, -i, -p |
| 516 | and -o. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 517 | Required flags: <name> |
| 518 | delete: deletes channel group specified with parameter -n. |
| 519 | Required flags: <name> |
| 520 | |
| 521 | -n: <string> name of channel pair. |
| 522 | -d: <string> description of channel pair. |
| 523 | -a: <string> admin state of channel pair. |
| 524 | -l: <enum> link up down trap enable type. |
| 525 | -r: <string> channel pair line rate. |
| 526 | -t: <string> channel pair type. |
| 527 | -g: <string> channel group reference. |
| 528 | -i: <int> gpon pon id interval. |
| 529 | -p: <string> channel partition reference. |
| 530 | -o: <enum> gpon pon id odn class. |
| 531 | |
| 532 | Example: |
| 533 | |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 534 | channel_pair create -n cp-1 -a up -r unplanned_cp_speed -t channelpair -g cg-1 |
| 535 | -i 0 -p cpart-1-1 -o class_a |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 536 | ''' |
| 537 | ) |
| 538 | |
| 539 | @options([ |
| 540 | make_option('-n', '--name', action="store", dest='name', type='string', |
| 541 | help='name of channel pair', default=None), |
| 542 | make_option('-d', '--description', action="store", dest='description', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 543 | type='string', help='description of channel pair', |
| 544 | default=None), |
| 545 | make_option('-a', '--admin_state', action="store", dest='enabled', |
| 546 | type='string', help='admin state of channel pair', |
| 547 | default=None), |
| 548 | make_option('-l', '--trap', action="store", |
| 549 | dest='link_up_down_trap_enable', type='string', |
| 550 | help='link up down trap enable type', default=None), |
| 551 | make_option('-r', '--cp_line_rate', action='store', |
| 552 | dest='channelpair_linerate', type='string', |
| 553 | help='channel pair linerate', default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 554 | make_option('-t', '--cp_type', action='store', dest='channelpair_type', |
| 555 | type='string', help='channel pair type', default=None), |
| 556 | make_option('-g', '--cg_ref', action='store', dest='channelgroup_ref', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 557 | type='string', help='channel group reference', |
| 558 | default=None), |
| 559 | make_option('-i', '--interval', action='store', |
| 560 | dest='gpon_ponid_interval', type='int', |
| 561 | help='gpon pon id interval', default=None), |
| 562 | make_option('-p', '--cpart_ref', action='store', |
| 563 | dest='channelpartition_ref', type='string', |
| 564 | help='channel partition reference', default=None), |
| 565 | make_option('-o', '--odn_class', action='store', |
| 566 | dest='gpon_ponid_odn_class', type='string', |
| 567 | help='gpon pon id odn class', default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 568 | ]) |
| 569 | |
| 570 | def do_channel_pair(self, line, opts): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 571 | """channel pair get, create -flags <attributes>, |
| 572 | update -flags <attributes>, delete -n <name>""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 573 | # Ensure that a valid sub-command was provided |
| 574 | if line.strip() not in {"get", "create", "update", "delete"}: |
| 575 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 576 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 577 | 'bold') + ' is not recognized') |
| 578 | return |
| 579 | |
| 580 | stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel()) |
| 581 | |
| 582 | if line.strip() == "get": |
| 583 | if self.device_id: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 584 | cg, cpart, cp, ct, vont, ont, venet = \ |
| 585 | self.get_interface_based_on_device() |
| 586 | print_pb_list_as_table("Channel Pairs for device ID = {}:" |
| 587 | .format(self.device_id), cp, {}, |
| 588 | self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 589 | else: |
| 590 | interface = stub.GetAllChannelpairConfig(Empty()) |
| 591 | print_pb_list_as_table("Channel Pairs:", |
| 592 | interface.channelpair_config, |
| 593 | {}, self.poutput) |
| 594 | return |
| 595 | |
| 596 | interface_instance = ChannelpairConfig(name = opts.name) |
| 597 | interface_instance.interface.name = opts.name |
| 598 | if opts.description: |
| 599 | interface_instance.interface.description = opts.description |
| 600 | interface_instance.interface.type = "channelpair" |
| 601 | if opts.enabled: |
| 602 | if opts.enabled == "up": |
| 603 | interface_instance.interface.enabled = True |
| 604 | elif opts.enabled == "down": |
| 605 | interface_instance.interface.enabled = False |
| 606 | else: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 607 | self.poutput( |
| 608 | self.colorize('Error: ', 'red') + self.colorize( |
| 609 | self.colorize('Invalid admin state parameter for \ |
| 610 | channel pair', 'blue'), 'bold')) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 611 | return |
| 612 | if opts.link_up_down_trap_enable: |
| 613 | types = ["trap_disabled", "trap_enabled"] |
| 614 | try: |
| 615 | assert opts.link_up_down_trap_enable in types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 616 | 'Invalid Enum value for Channel Pair link up down \ |
| 617 | trap enable type \'{}\''.format( |
| 618 | opts.link_up_down_trap_enable) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 619 | interface_instance.interface.link_up_down_trap_enable = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 620 | ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\ |
| 621 | values_by_name[opts.link_up_down_trap_enable.upper()].\ |
| 622 | number |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 623 | except AssertionError, e: |
| 624 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 625 | self.colorize(self.colorize(e.message, 'blue'), |
| 626 | 'bold')) |
| 627 | return |
| 628 | |
| 629 | if opts.channelpair_linerate: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 630 | interface_instance.data.channelpair_linerate = \ |
| 631 | opts.channelpair_linerate |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 632 | if opts.channelpair_type: |
| 633 | interface_instance.data.channelpair_type = opts.channelpair_type |
| 634 | if opts.channelgroup_ref: |
| 635 | interface_instance.data.channelgroup_ref = opts.channelgroup_ref |
| 636 | if opts.gpon_ponid_interval: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 637 | interface_instance.data.gpon_ponid_interval = \ |
| 638 | opts.gpon_ponid_interval |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 639 | if opts.channelpartition_ref: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 640 | interface_instance.data.channelpartition_ref = \ |
| 641 | opts.channelpartition_ref |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 642 | if opts.gpon_ponid_odn_class: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 643 | class_types = ["class_a", "class_b", "class_b_plus", "class_c", |
| 644 | "class_c_plus", "class_auto"] |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 645 | try: |
| 646 | assert opts.gpon_ponid_odn_class in class_types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 647 | 'Invalid enum value for Channel Pair gpon pon id odn \ |
| 648 | class \'{}\''.format(opts.gpon_ponid_odn_class) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 649 | interface_instance.data.gpon_ponid_odn_class = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 650 | bbf_fiber_types_pb2._PONIDODNCLASSTYPE.\ |
| 651 | values_by_name[opts.gpon_ponid_odn_class.upper()].number |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 652 | except AssertionError, e: |
| 653 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 654 | self.colorize(self.colorize(e.message, 'blue'), |
| 655 | 'bold')) |
| 656 | return |
| 657 | |
| 658 | if line.strip() == "create": |
| 659 | stub.CreateChannelpair(interface_instance) |
| 660 | elif line.strip() == "update": |
| 661 | stub.UpdateChannelpair(interface_instance) |
| 662 | elif line.strip() == "delete": |
| 663 | stub.DeleteChannelpair(interface_instance) |
| 664 | return |
| 665 | |
| 666 | def help_channel_termination(self): |
| 667 | self.poutput( |
| 668 | ''' |
| 669 | channel_termination [get | create | update | delete] [-i <id>] [-n <name>] |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 670 | [-d <description>] [-a <admin state>] |
| 671 | [-l <link up down trap enable type>] |
| 672 | [-r <channel pair reference>] |
| 673 | [-m <meant for type_b primary role>] |
| 674 | [-w <ngpon2 time wavelength division multiplexing |
| 675 | admin label>] |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 676 | [-p <ngpon2 ptp admin label>] [-s <xgs pon id>] |
| 677 | [-x <xgpon pon id>] [-g <gpon pon id>] [-t <pon tag>] |
| 678 | [-b <ber calc period>] [-l <location>] [-u <url to reach>] |
| 679 | |
| 680 | get: displays existing channel pairs |
| 681 | Required flags: None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 682 | create: creates channel pair with the parameters specified with -i -n, -d, -a, |
| 683 | -l, -r, -m, -w, -p, -s, -x, -g, -t, -b, -c and -u |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 684 | Required flags: <id>, <name> |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 685 | update: updates existing channel termination specified with -i and -n |
| 686 | parameters by changing its parameter values specified with -d, -a, -l, |
| 687 | -r, -m, -w, -p, -s, -x, -g, -b, -c, and -u |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 688 | Required flags: <id>, <name> |
| 689 | delete: deletes channel termination specified with parameter -i and -n. |
| 690 | Required flags: <id>, <name> |
| 691 | |
| 692 | -i: <string> device id. |
| 693 | -n: <string> name of channel termination. |
| 694 | -d: <string> description of channel termination. |
| 695 | -a: <string> admin state of channel termination. |
| 696 | -l: <enum> link up down trap enable type. |
| 697 | -r: <string> channel pair reference for this channel termination. |
| 698 | -m: <bool> meant for type_b primary role. |
| 699 | -w: <int> ngpon2 time wavelength division multiplexing admin label. |
| 700 | -p: <int> ngpon2 precision time protocol admin label. |
| 701 | -s: <int> xgs pon id. |
| 702 | -x: <int> xgpon pon id. |
| 703 | -g: <string> gpon pon id. |
| 704 | -t: <string> pon tag. |
| 705 | -b: <int> bit error rate calculation period. |
| 706 | -c: <string> location of channel termination. |
| 707 | -u: <string> url to reach channel termination. |
| 708 | |
| 709 | Example: |
| 710 | |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 711 | channel_termination create -i f90bb953f988 -n cterm-1 -a up -r cp-1 -m false |
| 712 | -w 0 -p 0 -s 0 -x 0 -b 0 -c raleigh -u localhost |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 713 | |
| 714 | ''' |
| 715 | ) |
| 716 | |
| 717 | @options([ |
| 718 | make_option('-i', '--id', action="store", dest='id', type='string', |
| 719 | help='device id', default=None), |
| 720 | make_option('-n', '--name', action="store", dest='name', type='string', |
| 721 | help='name of channel pair', default=None), |
| 722 | make_option('-d', '--description', action="store", dest='description', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 723 | type='string', help='description of channel termination', |
| 724 | default=None), |
| 725 | make_option('-a', '--admin_state', action="store", dest='enabled', |
| 726 | type='string', help='admin state of channel termination', |
| 727 | default=None), |
| 728 | make_option('-l', '--trap', action="store", |
| 729 | dest='link_up_down_trap_enable', type='string', |
| 730 | help='link up down trap enable type', default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 731 | make_option('-r', '--cp_ref', action='store', dest='channelpair_ref', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 732 | type='string', |
| 733 | help='channel pair reference for this channel termination', |
| 734 | default=None), |
| 735 | make_option('-m', '--type_b', action='store', |
| 736 | dest='meant_for_type_b_primary_role', type='string', |
| 737 | help='meant for type_b primary role', default=None), |
| 738 | make_option('-w', '--t_w_d_m', action='store', |
| 739 | dest='ngpon2_twdm_admin_label', type='int', |
| 740 | help='ngpon2 time wavelength division multiplexing admin \ |
| 741 | label', default=None), |
| 742 | make_option('-p', '--ptp', action='store', |
| 743 | dest='ngpon2_ptp_admin_label', type='int', |
| 744 | help='ngpon2 precision time protocol admin label', |
| 745 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 746 | make_option('-s', '--xgs', action='store', dest='xgs_ponid', |
| 747 | type='int', help='xgs pon id', default=None), |
| 748 | make_option('-x', '--xgpon', action='store', dest='xgpon_ponid', |
| 749 | type='int', help='xgpon pon id', default=None), |
| 750 | make_option('-g', '--gpon_pon', action='store', dest='gpon_ponid', |
| 751 | type='string', help='gpon pon id', default=None), |
| 752 | make_option('-t', '--pon', action='store', dest='pon_tag', |
| 753 | type='string', help='pon tag', default=None), |
| 754 | make_option('-b', '--ber', action='store', dest='ber_calc_period', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 755 | type='int', help='bit error rate calculation period', |
| 756 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 757 | make_option('-c', '--location', action='store', dest='location', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 758 | type='string', help='location of channel termination', |
| 759 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 760 | make_option('-u', '--url', action='store', dest='url_to_reach', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 761 | type='string', help='url to reach channel termination', |
| 762 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 763 | ]) |
| 764 | |
| 765 | def do_channel_termination(self, line, opts): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 766 | """channel termination get, create -flags <attributes>, |
| 767 | update -flags <attributes>, delete -i <id> -n <name>""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 768 | # Ensure that a valid sub-command was provided |
| 769 | if line.strip() not in {"get", "create", "update", "delete"}: |
| 770 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 771 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 772 | 'bold') + ' is not recognized') |
| 773 | return |
| 774 | |
| 775 | stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel()) |
| 776 | |
| 777 | if line.strip() == "get": |
| 778 | if self.device_id: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 779 | cg, cpart, cp, ct, vont, ont, venet = \ |
| 780 | self.get_interface_based_on_device() |
| 781 | print_pb_list_as_table( |
| 782 | "Channel Terminations for device ID = {}:" |
| 783 | .format(self.device_id), ct, {}, self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 784 | elif opts.id: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 785 | ct = stub.GetAllChannelterminationConfig( |
| 786 | voltha_pb2.ID(id=opts.id)).channeltermination_config |
| 787 | print_pb_list_as_table( |
| 788 | "Channel Terminations for device ID = {}:".format(opts.id), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 789 | ct, {}, self.poutput) |
| 790 | else: |
| 791 | devices = stub.ListDevices(Empty()) |
| 792 | for d in devices.items: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 793 | interface = stub.GetAllChannelterminationConfig( |
| 794 | voltha_pb2.ID(id=d.id)) |
| 795 | print_pb_list_as_table( |
| 796 | "Channel Terminations for device ID = {}:" |
| 797 | .format(d.id), interface.channeltermination_config, |
| 798 | {}, self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 799 | return |
| 800 | |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 801 | interface_instance = ChannelterminationConfig( |
| 802 | id = opts.id, name = opts.name) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 803 | interface_instance.interface.name = opts.name |
| 804 | if opts.description: |
| 805 | interface_instance.interface.description = opts.description |
| 806 | interface_instance.interface.type = "channel-termination" |
| 807 | if opts.enabled: |
| 808 | if opts.enabled == "up": |
| 809 | interface_instance.interface.enabled = True |
| 810 | elif opts.enabled == "down": |
| 811 | interface_instance.interface.enabled = False |
| 812 | else: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 813 | self.poutput( |
| 814 | self.colorize('Error: ', 'red') + self.colorize( |
| 815 | self.colorize('Invalid admin state parameter for \ |
| 816 | channel termination', 'blue'), 'bold')) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 817 | return |
| 818 | if opts.link_up_down_trap_enable: |
| 819 | types = ["trap_disabled", "trap_enabled"] |
| 820 | try: |
| 821 | assert opts.link_up_down_trap_enable in types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 822 | 'Invalid Enum value for Channel Termination link up \ |
| 823 | down trap enable type \'{}\''.format( |
| 824 | opts.link_up_down_trap_enable) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 825 | interface_instance.interface.link_up_down_trap_enable = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 826 | ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\ |
| 827 | values_by_name[opts.link_up_down_trap_enable.upper()].\ |
| 828 | number |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 829 | except AssertionError, e: |
| 830 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 831 | self.colorize(self.colorize(e.message, 'blue'), |
| 832 | 'bold')) |
| 833 | return |
| 834 | |
| 835 | if opts.channelpair_ref: |
| 836 | interface_instance.data.channelpair_ref = opts.channelpair_ref |
| 837 | if opts.meant_for_type_b_primary_role: |
| 838 | if opts.meant_for_type_b_primary_role == 'true': |
| 839 | interface_instance.data.meant_for_type_b_primary_role = True |
| 840 | elif opts.meant_for_type_b_primary_role == 'false': |
| 841 | interface_instance.data.meant_for_type_b_primary_role = False |
| 842 | else: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 843 | m = 'Invalid boolean value for Channel Termination \ |
| 844 | meant_for_type_b_primary_role \'{}\''.format( |
| 845 | opts.meant_for_type_b_primary_role) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 846 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 847 | self.colorize(self.colorize(m, 'blue'), |
| 848 | 'bold')) |
| 849 | return |
| 850 | if opts.ngpon2_twdm_admin_label: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 851 | interface_instance.data.ngpon2_twdm_admin_label = \ |
| 852 | opts.ngpon2_twdm_admin_label |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 853 | if opts.ngpon2_ptp_admin_label: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 854 | interface_instance.data.ngpon2_ptp_admin_label = \ |
| 855 | opts.ngpon2_ptp_admin_label |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 856 | if opts.xgs_ponid: |
| 857 | interface_instance.data.xgs_ponid = opts.xgs_ponid |
| 858 | if opts.xgpon_ponid: |
| 859 | interface_instance.data.xgpon_ponid = opts.xgpon_ponid |
| 860 | if opts.gpon_ponid: |
| 861 | interface_instance.data.gpon_ponid = opts.gpon_ponid |
| 862 | if opts.pon_tag: |
| 863 | interface_instance.data.pon_tag = opts.pon_tag |
| 864 | if opts.ber_calc_period: |
| 865 | interface_instance.data.ber_calc_period = opts.ber_calc_period |
| 866 | if opts.location: |
| 867 | interface_instance.data.location = opts.location |
| 868 | if opts.url_to_reach: |
| 869 | interface_instance.data.url_to_reach = opts.url_to_reach |
| 870 | |
| 871 | if line.strip() == "create": |
| 872 | stub.CreateChanneltermination(interface_instance) |
| 873 | elif line.strip() == "update": |
| 874 | stub.UpdateChanneltermination(interface_instance) |
| 875 | elif line.strip() == "delete": |
| 876 | stub.DeleteChanneltermination(interface_instance) |
| 877 | return |
| 878 | |
| 879 | def help_vont_ani(self): |
| 880 | self.poutput( |
| 881 | ''' |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 882 | vont_ani [get | create | update | delete] [-n <name>] [-d <description>] |
| 883 | [-a <admin state>] [-l <link up down trap enable type>] |
| 884 | [-p <parent reference>] [-s <expected serial number>] |
| 885 | [-i <expected registration id>] [-r <preferred channel pair>] |
| 886 | [-t <protection channel pair>] [-u <upstream channel speed>] |
| 887 | [-o <onu id>] |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 888 | |
| 889 | get: displays existing vont anis |
| 890 | Required flags: None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 891 | create: creates vont ani with the parameters specified with -n, -d, -a, -l, |
| 892 | -p, -s, -i, -r, -t, -u and -o. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 893 | Required flags: <name> |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 894 | update: updates existing vont ani specified with parameter -n by changing its |
| 895 | parameter values specified with -d, -a, -l, -p, -s, -i, -r, -t, -u |
| 896 | and -o. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 897 | Required flags: <name> |
| 898 | delete: deletes vont ani specified with parameter -n. |
| 899 | Required flags: <name> |
| 900 | |
| 901 | -n: <string> name of vont ani. |
| 902 | -d: <string> description of vont ani. |
| 903 | -a: <string> admin state of vont ani. |
| 904 | -l: <enum> link up down trap enable type. |
| 905 | -p: <string> parent reference of vont ani must be type of channel partition. |
| 906 | -s: <string> expected serial number of ONT. |
| 907 | -i: <string> expected registration id of ONT. |
| 908 | -r: <string> preferred channel pair must be type of channel pair. |
| 909 | -t: <string> protection channel pair must be type of channel pair. |
| 910 | -u: <int> upstream channel speed of traffic. |
| 911 | -o <int> ONU id. |
| 912 | |
| 913 | Example: |
| 914 | |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 915 | vont_ani create -n ontani-1-1-1 -a up -p cpart-1-1 -s ALCL00000001 -r cp-1 |
| 916 | -u 0 -o 1 |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 917 | ''' |
| 918 | ) |
| 919 | |
| 920 | @options([ |
| 921 | make_option('-n', '--name', action="store", dest='name', type='string', |
| 922 | help='name of vont ani', default=None), |
| 923 | make_option('-d', '--description', action="store", dest='description', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 924 | type='string', help='description of vont ani', |
| 925 | default=None), |
| 926 | make_option('-a', '--admin_state', action="store", dest='enabled', |
| 927 | type='string', help='admin state of vont ani', |
| 928 | default=None), |
| 929 | make_option('-l', '--trap', action="store", |
| 930 | dest='link_up_down_trap_enable', type='string', |
| 931 | help='link up down trap enable type', default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 932 | make_option('-p', '--parent_ref', action='store', dest='parent_ref', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 933 | type='string', |
| 934 | help='parent reference of vont ani must be type of \ |
| 935 | channel partition', default=None), |
| 936 | make_option('-s', '--e_ser_num', action='store', |
| 937 | dest='expected_serial_number', type='string', |
| 938 | help='expected serial number of ONT', default=None), |
| 939 | make_option('-i', '--e_reg_id', action='store', |
| 940 | dest='expected_registration_id', type='string', |
| 941 | help='expected registration id of ONT', default=None), |
| 942 | make_option('-r', '--pref_cp', action='store', |
| 943 | dest='preferred_chanpair', type='string', |
| 944 | help='preferred channel pair must be type of channel pair', |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 945 | default=None), |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 946 | make_option('-t', '--prot_cp', action='store', |
| 947 | dest='protection_chanpair', type='string', |
| 948 | help='protection channel pair must be type of channel \ |
| 949 | pair', default=None), |
| 950 | make_option('-u', '--up_cs', action='store', |
| 951 | dest='upstream_channel_speed', type='int', |
| 952 | help='upstream channel speed of traffic', default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 953 | make_option('-o', '--onu_id', action='store', dest='onu_id', |
| 954 | type='int', help='onu id', default=None), |
| 955 | ]) |
| 956 | |
| 957 | def do_vont_ani(self, line, opts): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 958 | """vont ani get, create -flags <attributes>, |
| 959 | update -flags <attributes>, delete -n <name>""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 960 | # Ensure that a valid sub-command was provided |
| 961 | if line.strip() not in {"get", "create", "update", "delete"}: |
| 962 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 963 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 964 | 'bold') + ' is not recognized') |
| 965 | return |
| 966 | |
| 967 | stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel()) |
| 968 | |
| 969 | if line.strip() == "get": |
| 970 | if self.device_id: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 971 | cg, cpart, cp, ct, vont, ont, venet = \ |
| 972 | self.get_interface_based_on_device() |
| 973 | print_pb_list_as_table("VOnt Anis for device ID = {}:" |
| 974 | .format(self.device_id), vont, {}, |
| 975 | self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 976 | else: |
| 977 | interface = stub.GetAllVOntaniConfig(Empty()) |
| 978 | print_pb_list_as_table("VOnt Anis:", |
| 979 | interface.v_ontani_config, |
| 980 | {}, self.poutput) |
| 981 | return |
| 982 | |
| 983 | interface_instance = VOntaniConfig(name = opts.name) |
| 984 | interface_instance.interface.name = opts.name |
| 985 | if opts.description: |
| 986 | interface_instance.interface.description = opts.description |
| 987 | interface_instance.interface.type = "v-ontani" |
| 988 | if opts.enabled: |
| 989 | if opts.enabled == "up": |
| 990 | interface_instance.interface.enabled = True |
| 991 | elif opts.enabled == "down": |
| 992 | interface_instance.interface.enabled = False |
| 993 | else: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 994 | self.poutput( |
| 995 | self.colorize('Error: ', 'red') + self.colorize( |
| 996 | self.colorize('Invalid admin state parameter for \ |
| 997 | vont ani', 'blue'), 'bold')) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 998 | return |
| 999 | if opts.link_up_down_trap_enable: |
| 1000 | types = ["trap_disabled", "trap_enabled"] |
| 1001 | try: |
| 1002 | assert opts.link_up_down_trap_enable in types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1003 | 'Invalid Enum value for VOnt Ani link up down trap \ |
| 1004 | enable type \'{}\''.format( |
| 1005 | opts.link_up_down_trap_enable) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1006 | interface_instance.interface.link_up_down_trap_enable = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1007 | ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\ |
| 1008 | values_by_name[opts.link_up_down_trap_enable.upper()].\ |
| 1009 | number |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1010 | except AssertionError, e: |
| 1011 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 1012 | self.colorize(self.colorize(e.message, 'blue'), |
| 1013 | 'bold')) |
| 1014 | return |
| 1015 | |
| 1016 | if opts.parent_ref: |
| 1017 | interface_instance.data.parent_ref = opts.parent_ref |
| 1018 | if opts.expected_serial_number: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1019 | interface_instance.data.expected_serial_number = \ |
| 1020 | opts.expected_serial_number |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1021 | if opts.expected_registration_id: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1022 | interface_instance.data.expected_registration_id = \ |
| 1023 | opts.expected_registration_id |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1024 | if opts.preferred_chanpair: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1025 | interface_instance.data.preferred_chanpair = \ |
| 1026 | opts.preferred_chanpair |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1027 | if opts.protection_chanpair: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1028 | interface_instance.data.protection_chanpair = \ |
| 1029 | opts.protection_chanpair |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1030 | if opts.upstream_channel_speed: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1031 | interface_instance.data.upstream_channel_speed = \ |
| 1032 | opts.upstream_channel_speed |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1033 | if opts.onu_id: |
| 1034 | interface_instance.data.onu_id = opts.onu_id |
| 1035 | |
| 1036 | if line.strip() == "create": |
| 1037 | stub.CreateVOntani(interface_instance) |
| 1038 | elif line.strip() == "update": |
| 1039 | stub.UpdateVOntani(interface_instance) |
| 1040 | elif line.strip() == "delete": |
| 1041 | stub.DeleteVOntani(interface_instance) |
| 1042 | return |
| 1043 | |
| 1044 | def help_ont_ani(self): |
| 1045 | self.poutput( |
| 1046 | ''' |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1047 | ont_ani [get | create | update | delete] [-n <name>] [-d <description>] |
| 1048 | [-a <admin state>] [-l <link up down trap enable type>] |
| 1049 | [-u <upstream fec indicator>] [-m <management gem port aes indicator>] |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1050 | |
| 1051 | get: displays existing ont anis |
| 1052 | Required flags: None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1053 | create: creates ont ani with the parameters specified with -n, -d, -a, -l, -u |
| 1054 | and -m. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1055 | Required flags: <name> |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1056 | update: updates existing ont ani specified with parameter -n by changing its |
| 1057 | parameter values specified with -d, -a, -l, -u and -m. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1058 | Required flags: <name> |
| 1059 | delete: deletes ont ani specified with parameter -n. |
| 1060 | Required flags: <name> |
| 1061 | |
| 1062 | -n: <string> name of ont ani. |
| 1063 | -d: <string> description of ont ani. |
| 1064 | -a: <string> admin state of ont ani. |
| 1065 | -l: <enum> link up down trap enable type. |
| 1066 | -u: <bool> upstream traffic fec indicator. |
| 1067 | -m: <bool> management gem port aes indicator. |
| 1068 | |
| 1069 | Example: |
| 1070 | |
| 1071 | ont_ani create -n ontani-1-1-1 -a up -u true -m true |
| 1072 | ''' |
| 1073 | ) |
| 1074 | |
| 1075 | @options([ |
| 1076 | make_option('-n', '--name', action="store", dest='name', type='string', |
| 1077 | help='name of ont ani', default=None), |
| 1078 | make_option('-d', '--description', action="store", dest='description', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1079 | type='string', help='description of ont ani', |
| 1080 | default=None), |
| 1081 | make_option('-a', '--admin_state', action="store", dest='enabled', |
| 1082 | type='string', help='admin state of ont ani', |
| 1083 | default=None), |
| 1084 | make_option('-l', '--trap', action="store", |
| 1085 | dest='link_up_down_trap_enable', type='string', |
| 1086 | help='link up down trap enable type', default=None), |
| 1087 | make_option('-u', '--up_fec', action='store', |
| 1088 | dest='upstream_fec_indicator', type='string', |
| 1089 | help='upstream traffic fec indicator', default=None), |
| 1090 | make_option('-m', '--maes', action='store', |
| 1091 | dest='mgnt_gemport_aes_indicator', type='string', |
| 1092 | help='management gem port aes indicator', default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1093 | ]) |
| 1094 | |
| 1095 | def do_ont_ani(self, line, opts): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1096 | """ont ani get, create -flags <attributes>, |
| 1097 | update -flags <attributes>, delete -n <name>""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1098 | # Ensure that a valid sub-command was provided |
| 1099 | if line.strip() not in {"get", "create", "update", "delete"}: |
| 1100 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 1101 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 1102 | 'bold') + ' is not recognized') |
| 1103 | return |
| 1104 | |
| 1105 | stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel()) |
| 1106 | |
| 1107 | if line.strip() == "get": |
| 1108 | if self.device_id: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1109 | cg, cpart, cp, ct, vont, ont, venet = \ |
| 1110 | self.get_interface_based_on_device() |
| 1111 | print_pb_list_as_table("Ont Anis for device ID = {}:".format( |
| 1112 | self.device_id), ont, {}, self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1113 | else: |
| 1114 | interface = stub.GetAllOntaniConfig(Empty()) |
| 1115 | print_pb_list_as_table("Ont Anis:", |
| 1116 | interface.ontani_config, |
| 1117 | {}, self.poutput) |
| 1118 | return |
| 1119 | |
| 1120 | interface_instance = OntaniConfig(name = opts.name) |
| 1121 | interface_instance.interface.name = opts.name |
| 1122 | if opts.description: |
| 1123 | interface_instance.interface.description = opts.description |
| 1124 | interface_instance.interface.type = "ontani" |
| 1125 | if opts.enabled: |
| 1126 | if opts.enabled == "up": |
| 1127 | interface_instance.interface.enabled = True |
| 1128 | elif opts.enabled == "down": |
| 1129 | interface_instance.interface.enabled = False |
| 1130 | else: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1131 | self.poutput( |
| 1132 | self.colorize('Error: ', 'red') + self.colorize( |
| 1133 | self.colorize('Invalid admin state parameter for \ |
| 1134 | ont ani', 'blue'), 'bold')) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1135 | return |
| 1136 | if opts.link_up_down_trap_enable: |
| 1137 | types = ["trap_disabled", "trap_enabled"] |
| 1138 | try: |
| 1139 | assert opts.link_up_down_trap_enable in types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1140 | 'Invalid Enum value for Ont Ani link up down trap \ |
| 1141 | enable type \'{}\''.format( |
| 1142 | opts.link_up_down_trap_enable) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1143 | interface_instance.interface.link_up_down_trap_enable = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1144 | ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\ |
| 1145 | values_by_name[opts.link_up_down_trap_enable.upper()].\ |
| 1146 | number |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1147 | except AssertionError, e: |
| 1148 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 1149 | self.colorize(self.colorize(e.message, 'blue'), |
| 1150 | 'bold')) |
| 1151 | return |
| 1152 | |
| 1153 | if opts.upstream_fec_indicator: |
| 1154 | if opts.upstream_fec_indicator == 'true': |
| 1155 | interface_instance.data.upstream_fec_indicator = True |
| 1156 | elif opts.upstream_fec_indicator == 'false': |
| 1157 | interface_instance.data.upstream_fec_indicator = False |
| 1158 | else: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1159 | m = 'Invalid boolean value for Ont Ani \ |
| 1160 | upstream_fec_indicator \'{}\''.format( |
| 1161 | opts.upstream_fec_indicator) |
| 1162 | self.poutput( |
| 1163 | self.colorize('Error: ', 'red') + self.colorize( |
| 1164 | self.colorize(m, 'blue'), 'bold')) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1165 | return |
| 1166 | if opts.mgnt_gemport_aes_indicator: |
| 1167 | if opts.mgnt_gemport_aes_indicator == 'true': |
| 1168 | interface_instance.data.mgnt_gemport_aes_indicator = True |
| 1169 | elif opts.mgnt_gemport_aes_indicator == 'false': |
| 1170 | interface_instance.data.mgnt_gemport_aes_indicator = False |
| 1171 | else: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1172 | m = 'Invalid boolean value for Ont Ani \ |
| 1173 | mgnt_gemport_aes_indicator \'{}\''.format( |
| 1174 | opts.mgnt_gemport_aes_indicator) |
| 1175 | self.poutput( |
| 1176 | self.colorize('Error: ', 'red') + self.colorize( |
| 1177 | self.colorize(m, 'blue'), 'bold')) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1178 | return |
| 1179 | |
| 1180 | if line.strip() == "create": |
| 1181 | stub.CreateOntani(interface_instance) |
| 1182 | elif line.strip() == "update": |
| 1183 | stub.UpdateOntani(interface_instance) |
| 1184 | elif line.strip() == "delete": |
| 1185 | stub.DeleteOntani(interface_instance) |
| 1186 | return |
| 1187 | |
| 1188 | def help_v_enet(self): |
| 1189 | self.poutput( |
| 1190 | ''' |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1191 | v_enet [get | create | update | delete] [-n <name>] [-d <description>] |
| 1192 | [-a <admin state>] [-l <link up down trap enable type>] |
| 1193 | [-r <ont ani reference>] |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1194 | |
| 1195 | get: displays existing venets |
| 1196 | Required flags: None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1197 | create: creates venet with the parameters specified with -n, -d, -a, -l, |
| 1198 | and -r. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1199 | Required flags: <name> |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1200 | update: updates existing venet specified with parameter -n by changing its |
| 1201 | parameter values specified with -d, -a, -l, -r. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1202 | Required flags: <name> |
| 1203 | delete: deletes venet specified with parameter -n. |
| 1204 | Required flags: <name> |
| 1205 | |
| 1206 | -n: <string> name of venet. |
| 1207 | -d: <string> description of venet. |
| 1208 | -a: <string> admin state of venet. |
| 1209 | -l: <enum> link up down trap enable type. |
| 1210 | -r: <string> ont ani reference of this venet. |
| 1211 | |
| 1212 | Example: |
| 1213 | |
| 1214 | v_enet create -n venet-1 -a up -r ontani-1-1-1 |
| 1215 | ''' |
| 1216 | ) |
| 1217 | |
| 1218 | @options([ |
| 1219 | make_option('-n', '--name', action="store", dest='name', type='string', |
| 1220 | help='name of venet', default=None), |
| 1221 | make_option('-d', '--description', action="store", dest='description', |
| 1222 | type='string', help='description of venet', default=None), |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1223 | make_option('-a', '--admin_state', action="store", dest='enabled', |
| 1224 | type='string', help='admin state of venet', default=None), |
| 1225 | make_option('-l', '--trap', action="store", |
| 1226 | dest='link_up_down_trap_enable', type='string', |
| 1227 | help='link up down trap enable type', default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1228 | make_option('-r', '--ont_ref', action='store', dest='v_ontani_ref', |
| 1229 | type='string', help='ont ani reference', default=None), |
| 1230 | ]) |
| 1231 | |
| 1232 | def do_v_enet(self, line, opts): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1233 | """v_enet get, create -flags <attributes>, |
| 1234 | update -flags <attributes>, delete -n <name>""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1235 | # Ensure that a valid sub-command was provided |
| 1236 | if line.strip() not in {"get", "create", "update", "delete"}: |
| 1237 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 1238 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 1239 | 'bold') + ' is not recognized') |
| 1240 | return |
| 1241 | |
| 1242 | stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel()) |
| 1243 | |
| 1244 | if line.strip() == "get": |
| 1245 | if self.device_id: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1246 | cg, cpart, cp, ct, vont, ont, venet = \ |
| 1247 | self.get_interface_based_on_device() |
| 1248 | print_pb_list_as_table("VEnet for device ID = {}:" |
| 1249 | .format(self.device_id), venet, {}, |
| 1250 | self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1251 | else: |
| 1252 | interface = stub.GetAllVEnetConfig(Empty()) |
| 1253 | print_pb_list_as_table("VEnets:", |
| 1254 | interface.v_enet_config, |
| 1255 | {}, self.poutput) |
| 1256 | return |
| 1257 | |
| 1258 | interface_instance = VEnetConfig(name = opts.name) |
| 1259 | interface_instance.interface.name = opts.name |
| 1260 | if opts.description: |
| 1261 | interface_instance.interface.description = opts.description |
| 1262 | interface_instance.interface.type = "v-enet" |
| 1263 | if opts.enabled: |
| 1264 | if opts.enabled == "up": |
| 1265 | interface_instance.interface.enabled = True |
| 1266 | elif opts.enabled == "down": |
| 1267 | interface_instance.interface.enabled = False |
| 1268 | else: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1269 | self.poutput( |
| 1270 | self.colorize('Error: ', 'red') + self.colorize( |
| 1271 | self.colorize('Invalid admin state parameter for \ |
| 1272 | venet', 'blue'), 'bold')) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1273 | return |
| 1274 | if opts.link_up_down_trap_enable: |
| 1275 | types = ["trap_disabled", "trap_enabled"] |
| 1276 | try: |
| 1277 | assert opts.link_up_down_trap_enable in types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1278 | 'Invalid Enum value for Venet link up down trap \ |
| 1279 | enable type \'{}\''.format( |
| 1280 | opts.link_up_down_trap_enable) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1281 | interface_instance.interface.link_up_down_trap_enable = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1282 | ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\ |
| 1283 | values_by_name[opts.link_up_down_trap_enable.upper()].\ |
| 1284 | number |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1285 | except AssertionError, e: |
| 1286 | self.poutput(self.colorize('Error: ', 'red') + \ |
| 1287 | self.colorize(self.colorize(e.message, 'blue'), |
| 1288 | 'bold')) |
| 1289 | return |
| 1290 | |
| 1291 | if opts.v_ontani_ref: |
| 1292 | interface_instance.data.v_ontani_ref = opts.v_ontani_ref |
| 1293 | |
| 1294 | if line.strip() == "create": |
| 1295 | stub.CreateVEnet(interface_instance) |
| 1296 | elif line.strip() == "update": |
| 1297 | stub.UpdateVEnet(interface_instance) |
| 1298 | elif line.strip() == "delete": |
| 1299 | stub.DeleteVEnet(interface_instance) |
| 1300 | return |