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