blob: 7e3d8c2ae93ad10a56c1327a912e0b8fe42c2f42 [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 , \
Nikolay Titov176f1db2017-08-10 12:38:43 -040035 VOntaniConfig, AllVEnetConfig , VEnetConfig, \
36 AllTrafficDescriptorProfileData, AllTcontsConfigData, AllGemportsConfigData
37from voltha.protos.bbf_fiber_traffic_descriptor_profile_body_pb2 import \
38 TrafficDescriptorProfileData
39from voltha.protos.bbf_fiber_tcont_body_pb2 import TcontsConfigData
40from voltha.protos.bbf_fiber_gemport_body_pb2 import GemportsConfigData
Nikolay Titov89004ec2017-06-19 18:22:42 -040041
42_ = third_party
Nikolay Titov176f1db2017-08-10 12:38:43 -040043from voltha.protos import voltha_pb2, bbf_fiber_types_pb2, \
44 ietf_interfaces_pb2, bbf_fiber_traffic_descriptor_profile_body_pb2
Nikolay Titov89004ec2017-06-19 18:22:42 -040045import sys
46from google.protobuf.json_format import MessageToDict
47
48# Since proto3 won't send fields that are set to 0/false/"" any object that
49# might have those values set in them needs to be replicated here such that the
50# fields can be adequately
51
52class XponCli(Cmd):
53
54 def __init__(self, get_channel, device_id):
55 Cmd.__init__(self)
56 self.get_channel = get_channel
57 self.device_id = device_id
58 self.prompt = '(' + self.colorize(
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -040059 self.colorize('voltha-xpon {}'.format(device_id), 'green'),
60 'bold') + ') '
Nikolay Titov89004ec2017-06-19 18:22:42 -040061
62 def cmdloop(self):
63 self._cmdloop()
64
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -040065 def get_ref_interfaces(self, all_interfaces, ref_interfaces):
66 interface_list = []
Nikolay Titov176f1db2017-08-10 12:38:43 -040067 interface_name_list = []
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -040068 if not all_interfaces:
69 return interface_list
70 if isinstance(all_interfaces[0], (ChannelgroupConfig,
71 ChannelpartitionConfig,
Nikolay Titov176f1db2017-08-10 12:38:43 -040072 ChannelpairConfig, OntaniConfig,
73 TrafficDescriptorProfileData)):
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -040074 for interface in all_interfaces:
Nikolay Titov176f1db2017-08-10 12:38:43 -040075 if interface.name in ref_interfaces and \
76 interface.name not in interface_name_list:
77 interface_name_list.append(interface.name)
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -040078 interface_list.append(interface)
79 elif isinstance(all_interfaces[0], VOntaniConfig):
80 for interface in all_interfaces:
Nikolay Titov176f1db2017-08-10 12:38:43 -040081 if interface.data.parent_ref in ref_interfaces and \
82 interface.name not in interface_name_list:
83 interface_name_list.append(interface.name)
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -040084 interface_list.append(interface)
85 elif isinstance(all_interfaces[0], VEnetConfig):
86 for interface in all_interfaces:
Nikolay Titov176f1db2017-08-10 12:38:43 -040087 if interface.data.v_ontani_ref in ref_interfaces and \
88 interface.name not in interface_name_list:
89 interface_name_list.append(interface.name)
90 interface_list.append(interface)
91 elif isinstance(all_interfaces[0], TcontsConfigData):
92 for interface in all_interfaces:
93 if interface.interface_reference in ref_interfaces and \
94 interface.name not in interface_name_list:
95 interface_name_list.append(interface.name)
96 interface_list.append(interface)
97 elif isinstance(all_interfaces[0], GemportsConfigData):
98 for interface in all_interfaces:
99 if interface.itf_ref in ref_interfaces and \
100 interface.name not in interface_name_list:
101 interface_name_list.append(interface.name)
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400102 interface_list.append(interface)
103 return interface_list
104
Nikolay Titov89004ec2017-06-19 18:22:42 -0400105 def get_interface_based_on_device(self):
Nikolay Titov176f1db2017-08-10 12:38:43 -0400106 stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel())
107 try:
108 channel_terminations = stub.GetAllChannelterminationConfig(
109 voltha_pb2.ID(id=self.device_id)).channeltermination_config
110 except Exception:
111 self.poutput(
112 self.colorize('Error: ', 'red') + 'No device id ' \
113 + self.colorize(device_id, 'blue') + ' is found')
114 return
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400115 channel_pairs = self.get_ref_interfaces(
116 stub.GetAllChannelpairConfig(Empty()).channelpair_config,
117 dict((dt.data.channelpair_ref, dt) for dt in channel_terminations))
118 channel_partitions = self.get_ref_interfaces(
119 stub.GetAllChannelpartitionConfig(Empty()).channelpartition_config,
120 dict((dt.data.channelpartition_ref, dt) for dt in channel_pairs))
121 channel_groups = self.get_ref_interfaces(
122 stub.GetAllChannelgroupConfig(Empty()).channelgroup_config,
123 dict((dt.data.channelgroup_ref, dt) for dt in channel_partitions))
124 vont_anis = self.get_ref_interfaces(
125 stub.GetAllVOntaniConfig(Empty()).v_ontani_config,
126 dict((dt.name, dt) for dt in channel_partitions))
127 ont_anis = self.get_ref_interfaces(
128 stub.GetAllOntaniConfig(Empty()).ontani_config,
129 dict((dt.name, dt) for dt in vont_anis))
130 venets = self.get_ref_interfaces(
131 stub.GetAllVEnetConfig(Empty()).v_enet_config,
132 dict((dt.name, dt) for dt in vont_anis))
Nikolay Titov176f1db2017-08-10 12:38:43 -0400133 tconts = self.get_ref_interfaces(
134 stub.GetAllTcontsConfigData(Empty()).tconts_config,
135 dict((dt.name, dt) for dt in vont_anis))
136 traffic_descriptor_profiles = self.get_ref_interfaces(
137 stub.GetAllTrafficDescriptorProfileData(Empty()).
138 traffic_descriptor_profiles,
139 dict((dt.traffic_descriptor_profile_ref, dt) for dt in tconts))
140 gemports = self.get_ref_interfaces(
141 stub.GetAllGemportsConfigData(Empty()).gemports_config,
142 dict((dt.name, dt) for dt in venets))
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400143 return channel_groups, channel_partitions, channel_pairs,\
Nikolay Titov176f1db2017-08-10 12:38:43 -0400144 channel_terminations, vont_anis, ont_anis, venets, \
145 traffic_descriptor_profiles, tconts, gemports
Nikolay Titov89004ec2017-06-19 18:22:42 -0400146
147 do_exit = Cmd.do_quit
148
149 def do_quit(self, line):
150 return self._STOP_AND_EXIT
151
152 def do_show(self, line):
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400153 """Show detailed information of each interface based on device ID
154 or all interfaces"""
Nikolay Titov176f1db2017-08-10 12:38:43 -0400155 stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel())
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400156 device_id = self.device_id
Nikolay Titov89004ec2017-06-19 18:22:42 -0400157 if line.strip():
Nikolay Titov176f1db2017-08-10 12:38:43 -0400158 self.device_id = line.strip()
159 if self.device_id:
160 cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400161 self.get_interface_based_on_device()
Nikolay Titov176f1db2017-08-10 12:38:43 -0400162 print_pb_list_as_table("Channel Groups for device ID = {}:".format(
163 self.device_id), cg, {}, self.poutput)
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400164 print_pb_list_as_table("Channel Partitions for device ID = {}:"
Nikolay Titov176f1db2017-08-10 12:38:43 -0400165 .format(self.device_id),cpart, {},
166 self.poutput)
167 print_pb_list_as_table("Channel Pairs: for device ID = {}:".format(
168 self.device_id), cp, {}, self.poutput)
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400169 print_pb_list_as_table("Channel Terminations for device ID = {}:"
Nikolay Titov176f1db2017-08-10 12:38:43 -0400170 .format(self.device_id), ct, {},
171 self.poutput)
172 print_pb_list_as_table("VOnt Anis for device ID = {}:".format(
173 self.device_id), vont, {}, self.poutput)
174 print_pb_list_as_table("Ont Anis for device ID = {}:".format(
175 self.device_id), ont, {}, self.poutput)
176 print_pb_list_as_table("VEnets for device ID = {}:".format(
177 self.device_id), venet, {}, self.poutput)
178 print_pb_list_as_table(
179 "Traffic Descriptor Profiles for device ID = {}:".format(
180 self.device_id), tdp, {}, self.poutput)
181 print_pb_list_as_table("TConts for device ID = {}:".format(
182 self.device_id), tcont, {}, self.poutput)
183 print_pb_list_as_table("Gem Ports for device ID = {}:".format(
184 self.device_id), gemport, {}, self.poutput)
185 self.device_id = device_id
Nikolay Titov89004ec2017-06-19 18:22:42 -0400186 else:
187 interface = stub.GetAllChannelgroupConfig(Empty())
188 print_pb_list_as_table("Channel Groups:",
Nikolay Titov176f1db2017-08-10 12:38:43 -0400189 interface.channelgroup_config, {},
190 self.poutput)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400191 interface = stub.GetAllChannelpartitionConfig(Empty())
192 print_pb_list_as_table("Channel Partitions:",
Nikolay Titov176f1db2017-08-10 12:38:43 -0400193 interface.channelpartition_config, {},
194 self.poutput)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400195 interface = stub.GetAllChannelpairConfig(Empty())
196 print_pb_list_as_table("Channel Pairs:",
Nikolay Titov176f1db2017-08-10 12:38:43 -0400197 interface.channelpair_config, {},
198 self.poutput)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400199 devices = stub.ListDevices(Empty())
200 for d in devices.items:
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400201 interface = stub.GetAllChannelterminationConfig(
202 voltha_pb2.ID(id=d.id))
203 print_pb_list_as_table(
204 "Channel Terminations for device ID = {}:"
205 .format(d.id), interface.channeltermination_config,
206 {}, self.poutput)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400207 interface = stub.GetAllVOntaniConfig(Empty())
Nikolay Titov176f1db2017-08-10 12:38:43 -0400208 print_pb_list_as_table("VOnt Anis:", interface.v_ontani_config, {},
209 self.poutput)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400210 interface = stub.GetAllOntaniConfig(Empty())
Nikolay Titov176f1db2017-08-10 12:38:43 -0400211 print_pb_list_as_table("Ont Anis:", interface.ontani_config, {},
212 self.poutput)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400213 interface = stub.GetAllVEnetConfig(Empty())
Nikolay Titov176f1db2017-08-10 12:38:43 -0400214 print_pb_list_as_table("VEnets:", interface.v_enet_config, {},
215 self.poutput)
216 traffic_descriptor = \
217 stub.GetAllTrafficDescriptorProfileData(Empty())
218 print_pb_list_as_table(
219 "Traffic Descriptor Profiles:",
220 traffic_descriptor.traffic_descriptor_profiles, {},
221 self.poutput)
222 tconts = stub.GetAllTcontsConfigData(Empty())
223 print_pb_list_as_table("TConts:", tconts.tconts_config, {},
224 self.poutput)
225 gemports = stub.GetAllGemportsConfigData(Empty())
226 print_pb_list_as_table("Gem Ports:", gemports.gemports_config, {},
227 self.poutput)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400228
229 def help_channel_group(self):
230 self.poutput(
231'''
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400232channel_group [get | create | update | delete] [-n <name>] [-d <description>]
233 [-a <admin state>] [-l <link up down trap enable type>]
234 [-p <polling period>] [-s <system id>] [-r <raman mitigation>]
Nikolay Titov89004ec2017-06-19 18:22:42 -0400235
236get: displays existing channel groups
237 Required flags: None
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400238create: creates channel group with the parameters specified with -n, -d, -a,
239 -l, -p, -s and -r.
Nikolay Titov89004ec2017-06-19 18:22:42 -0400240 Required flags: <name>
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400241update: updates existing channel group specified with parameter -n by changing
242 its parameter values specified with -d, -a, -l, -p, -s and -r.
Nikolay Titov89004ec2017-06-19 18:22:42 -0400243 Required flags: <name>
244delete: deletes channel group specified with parameter -n.
245 Required flags: <name>
246
247-n: <string> name of channel group.
248-d: <string> description of channel group.
249-a: <string> admin state of channel group.
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400250-l: <enum> link up down trap enable type.
Nikolay Titov89004ec2017-06-19 18:22:42 -0400251-p: <int> polling period for channel group.
252-s: <string> system id for channel group.
253-r: <enum> raman mitigation for channel group.
254
255Example:
256
Nikolay Titov176f1db2017-08-10 12:38:43 -0400257channel_group create -n "Manhattan" -d "Channel Group for Manhattan" -a up
258 -p 100 -s 000000 -r raman_none
Nikolay Titov89004ec2017-06-19 18:22:42 -0400259'''
260 )
261
262 @options([
263 make_option('-n', '--name', action="store", dest='name', type='string',
264 help='name of channel group', default=None),
265 make_option('-d', '--description', action="store", dest='description',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400266 type='string', help='description of channel group',
267 default=None),
268 make_option('-a', '--admin_state', action="store", dest='enabled',
269 type='string', help='admin state of channel group',
270 default=None),
271 make_option('-l', '--trap', action="store",
272 dest='link_up_down_trap_enable', type='string',
273 help='link up down trap enable type', default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400274 make_option('-p', '--pp', action='store', dest='polling_period',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400275 type='int', help='polling period of channel group',
276 default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400277 make_option('-s', '--sid', action='store', dest='system_id',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400278 type='string', help='system id of channel group',
279 default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400280 make_option('-r', '--rm', action='store', dest='raman_mitigation',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400281 type='string', help='raman mitigation of channel group',
282 default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400283 ])
284
285 def do_channel_group(self, line, opts):
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400286 """channel group get, create -flags <attributes>,
287 update -flags <attributes>, delete -n <name>"""
Nikolay Titov89004ec2017-06-19 18:22:42 -0400288 # Ensure that a valid sub-command was provided
289 if line.strip() not in {"get", "create", "update", "delete"}:
Nikolay Titov176f1db2017-08-10 12:38:43 -0400290 self.poutput(self.colorize('Error: ', 'red') +
291 self.colorize(self.colorize(line.strip(), 'blue'),
292 'bold') + ' is not recognized')
Nikolay Titov89004ec2017-06-19 18:22:42 -0400293 return
294
Nikolay Titov176f1db2017-08-10 12:38:43 -0400295 stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel())
Nikolay Titov89004ec2017-06-19 18:22:42 -0400296
297 if line.strip() == "get":
298 if self.device_id:
Nikolay Titov176f1db2017-08-10 12:38:43 -0400299 cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400300 self.get_interface_based_on_device()
301 print_pb_list_as_table("Channel Groups for device ID = {}:"
302 .format(self.device_id),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400303 cg, {}, self.poutput)
304 else:
305 interface = stub.GetAllChannelgroupConfig(Empty())
306 print_pb_list_as_table("Channel Groups:",
307 interface.channelgroup_config,
308 {}, self.poutput)
309 return
Nikolay Titov176f1db2017-08-10 12:38:43 -0400310 try:
311 interface_instance = ChannelgroupConfig(name = opts.name)
312 interface_instance.interface.name = opts.name
313 if opts.description:
314 interface_instance.interface.description = opts.description
315 interface_instance.interface.type = "channelgroup"
316 if opts.enabled:
317 if opts.enabled == "up":
318 interface_instance.interface.enabled = True
319 elif opts.enabled == "down":
320 interface_instance.interface.enabled = False
321 else:
322 self.poutput(
323 self.colorize('Error: ', 'red') + self.colorize(
324 self.colorize('Invalid admin state parameter for \
325 channel group', 'blue'), 'bold'))
326 return
327 if opts.link_up_down_trap_enable:
328 types = ["trap_disabled", "trap_enabled"]
Nikolay Titov89004ec2017-06-19 18:22:42 -0400329 assert opts.link_up_down_trap_enable in types, \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400330 'Invalid Enum value for Channel Group link up down trap \
331 enable type \'{}\''.format(opts.link_up_down_trap_enable)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400332 interface_instance.interface.link_up_down_trap_enable = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400333 ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\
334 values_by_name[opts.link_up_down_trap_enable.upper()]\
335 .number
Nikolay Titov176f1db2017-08-10 12:38:43 -0400336 if opts.polling_period:
337 interface_instance.data.polling_period = opts.polling_period
338 if opts.raman_mitigation:
339 raman_mitigations = ["raman_none", "raman_miller",
340 "raman_8b10b"]
Nikolay Titov89004ec2017-06-19 18:22:42 -0400341 assert opts.raman_mitigation in raman_mitigations, \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400342 'Invalid Enum value for Channel Group raman mitigation\
343 \'{}\''.format(opts.raman_mitigation)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400344 interface_instance.data.raman_mitigation = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400345 bbf_fiber_types_pb2._RAMANMITIGATIONTYPE.\
346 values_by_name[opts.raman_mitigation.upper()].number
Nikolay Titov176f1db2017-08-10 12:38:43 -0400347 if opts.system_id:
348 interface_instance.data.system_id = opts.system_id
349 if line.strip() == "create":
350 stub.CreateChannelgroup(interface_instance)
351 elif line.strip() == "update":
352 stub.UpdateChannelgroup(interface_instance)
353 elif line.strip() == "delete":
354 stub.DeleteChannelgroup(interface_instance)
355 return
356 except Exception, e:
357 self.poutput(
358 self.colorize('Error: ', 'red') +
359 self.colorize(self.colorize(e.message, 'blue'), 'bold'))
360 return
Nikolay Titov89004ec2017-06-19 18:22:42 -0400361
362 def help_channel_partition(self):
363 self.poutput(
364'''
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400365channel_partition [get | create | update | delete] [-n <name>]
366 [-d <description>] [-a <admin state>]
367 [-l <link up down trap enable type>]
368 [-r <differential fiber distance>]
369 [-o <closest ont distance>] [-f <fec downstream>]
370 [-m <multicast aes indicator>] [-u <authentication method>]
371 [-c <channel group reference>]
Nikolay Titov89004ec2017-06-19 18:22:42 -0400372
373get: displays existing channel partitions
374 Required flags: None
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400375create: creates channel partition with the parameters specified with -n, -d,
376 -a, -l, -r, -o, -f, -m, -u and -c.
Nikolay Titov89004ec2017-06-19 18:22:42 -0400377 Required flags: <name>, <channel group reference>
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400378update: updates existing channel partition specified with parameter -n by
379 changing its parameter values specified with -d, -a, -l, -r, -o, -f,
380 -m, -u and -c.
Nikolay Titov89004ec2017-06-19 18:22:42 -0400381 Required flags: <name>
382delete: deletes channel group specified with parameter -n.
383 Required flags: <name>
384
385-n: <string> name of channel partition.
386-d: <string> description of channel partition.
387-a: <string> admin state of channel partition.
388-l: <enum> link up down trap enable type.
389-r: <int> differential fiber distance.
390-o: <int> closest ont distance.
391-f: <bool> forward and error correction downstream.
392-m: <bool> multicast aes indicator of channel partition.
393-u: <enum> authentication method.
394-c: <string> channel group reference for this channel partition.
395
396Example:
397
Nikolay Titov176f1db2017-08-10 12:38:43 -0400398channel_partition create -n "Freedom Tower"
399 -d "Channel Partition for Freedom Tower in Manhattan"
400 -a up -r 20 -o 0 -f false -m false -u serial_number
401 -c "Manhattan"
Nikolay Titov89004ec2017-06-19 18:22:42 -0400402'''
403 )
404
405 @options([
406 make_option('-n', '--name', action="store", dest='name', type='string',
407 help='name of channel partition', default=None),
408 make_option('-d', '--description', action="store", dest='description',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400409 type='string', help='description of channel partition',
410 default=None),
411 make_option('-a', '--admin_state', action="store", dest='enabled',
412 type='string', help='admin state of channel partition',
413 default=None),
414 make_option('-l', '--trap', action="store",
415 dest='link_up_down_trap_enable', type='string',
416 help='link up down trap enable type', default=None),
417 make_option('-r', '--diff_fib_dist', action='store',
418 dest='differential_fiber_distance', type='int',
419 help='differential fiber distance', default=None),
420 make_option('-o', '--ont_dist', action='store',
421 dest='closest_ont_distance', type='int',
422 help='closest ont distance', default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400423 make_option('-f', '--fec_ds', action='store', dest='fec_downstream',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400424 type='string',
425 help='forward and error correction downstream',
426 default=None),
427 make_option('-m', '--mc_aes', action='store',
428 dest='multicast_aes_indicator', type='string',
429 help='multicast aes indicator of channel partition',
430 default=None),
431 make_option('-u', '--auth', action='store',
432 dest='authentication_method', type='string',
433 help='authentication method', default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400434 make_option('-c', '--cg_ref', action='store', dest='channelgroup_ref',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400435 type='string',
436 help='channel group reference for this channel partition',
437 default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400438 ])
439
440 def do_channel_partition(self, line, opts):
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400441 """channel partition get, create -flags <attributes>,
442 update -flags <attributes>, delete -n <name>"""
Nikolay Titov89004ec2017-06-19 18:22:42 -0400443 # Ensure that a valid sub-command was provided
444 if line.strip() not in {"get", "create", "update", "delete"}:
Nikolay Titov176f1db2017-08-10 12:38:43 -0400445 self.poutput(self.colorize('Error: ', 'red') +
446 self.colorize(self.colorize(line.strip(), 'blue'),
447 'bold') + ' is not recognized')
Nikolay Titov89004ec2017-06-19 18:22:42 -0400448 return
449
Nikolay Titov176f1db2017-08-10 12:38:43 -0400450 stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel())
Nikolay Titov89004ec2017-06-19 18:22:42 -0400451
452 if line.strip() == "get":
453 if self.device_id:
Nikolay Titov176f1db2017-08-10 12:38:43 -0400454 cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400455 self.get_interface_based_on_device()
456 print_pb_list_as_table("Channel Partitions for device ID = {}:"
457 .format(self.device_id), cpart, {},
458 self.poutput)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400459 else:
460 interface = stub.GetAllChannelpartitionConfig(Empty())
461 print_pb_list_as_table("Channel Partitions:",
462 interface.channelpartition_config,
463 {}, self.poutput)
464 return
Nikolay Titov176f1db2017-08-10 12:38:43 -0400465 try:
466 interface_instance = ChannelpartitionConfig(name = opts.name)
467 interface_instance.interface.name = opts.name
468 if opts.description:
469 interface_instance.interface.description = opts.description
470 interface_instance.interface.type = "channelpartition"
471 if opts.enabled:
472 if opts.enabled == "up":
473 interface_instance.interface.enabled = True
474 elif opts.enabled == "down":
475 interface_instance.interface.enabled = False
476 else:
477 self.poutput(
478 self.colorize('Error: ', 'red') + self.colorize(
479 self.colorize('Invalid admin state parameter for \
480 channel partition', 'blue'), 'bold'))
481 return
482 if opts.link_up_down_trap_enable:
483 types = ["trap_disabled", "trap_enabled"]
Nikolay Titov89004ec2017-06-19 18:22:42 -0400484 assert opts.link_up_down_trap_enable in types, \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400485 'Invalid Enum value for Channel Partition link up \
486 down trap enable type \'{}\''\
Nikolay Titov89004ec2017-06-19 18:22:42 -0400487 .format(opts.link_up_down_trap_enable)
488 interface_instance.interface.link_up_down_trap_enable = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400489 ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\
490 values_by_name[opts.link_up_down_trap_enable.upper()].\
491 number
Nikolay Titov176f1db2017-08-10 12:38:43 -0400492 if opts.differential_fiber_distance:
493 interface_instance.data.differential_fiber_distance = \
494 opts.differential_fiber_distance
495 if opts.closest_ont_distance:
496 interface_instance.data.closest_ont_distance = \
497 opts.closest_ont_distance
498 if opts.fec_downstream:
499 if opts.fec_downstream == 'true':
500 interface_instance.data.fec_downstream = True
501 elif opts.fec_downstream == 'false':
502 interface_instance.data.fec_downstream = False
503 else:
504 m = 'Invalid boolean value for Channel Partition \
505 fec_downstream \'{}\''.format(opts.fec_downstream)
506 self.poutput(
507 self.colorize('Error: ', 'red') +
508 self.colorize(self.colorize(m, 'blue'),'bold'))
509 return
510 if opts.multicast_aes_indicator:
511 if opts.multicast_aes_indicator == 'true':
512 interface_instance.data.multicast_aes_indicator = True
513 elif opts.multicast_aes_indicator == 'false':
514 interface_instance.data.multicast_aes_indicator = False
515 else:
516 m = 'Invalid boolean value for Channel Partition \
517 multicast_aes_indicator \'{}\''.format(
518 opts.multicast_aes_indicator)
519 self.poutput(
520 self.colorize('Error: ', 'red') +
521 self.colorize(self.colorize(m, 'blue'), 'bold'))
522 return
523 if opts.authentication_method:
524 auth_method_types = \
525 ["serial_number", "loid", "registration_id",
526 "omci", "dot1x"]
Nikolay Titov89004ec2017-06-19 18:22:42 -0400527 assert opts.authentication_method in auth_method_types, \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400528 'Invalid Enum value for Channel Partition \
529 authentication method \'{}\''.format(
530 opts.authentication_method)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400531 interface_instance.data.authentication_method = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400532 bbf_fiber_types_pb2._AUTHMETHODTYPE.\
533 values_by_name[opts.authentication_method.upper()].number
Nikolay Titov176f1db2017-08-10 12:38:43 -0400534 if opts.channelgroup_ref:
535 interface_instance.data.channelgroup_ref = \
536 opts.channelgroup_ref
537 if line.strip() == "create":
538 stub.CreateChannelpartition(interface_instance)
539 elif line.strip() == "update":
540 stub.UpdateChannelpartition(interface_instance)
541 elif line.strip() == "delete":
542 stub.DeleteChannelpartition(interface_instance)
543 return
544 except Exception, e:
545 self.poutput(
546 self.colorize('Error: ', 'red') +
547 self.colorize(self.colorize(e.message, 'blue'), 'bold'))
548 return
Nikolay Titov89004ec2017-06-19 18:22:42 -0400549
550 def help_channel_pair(self):
551 self.poutput(
552'''
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400553channel_pair [get | create | update | delete] [-n <name>] [-d <description>]
554 [-a <admin state>] [-l <link up down trap enable type>]
555 [-r <channel pair line rate>] [-t <channel pair type>]
556 [-g <channel group reference>] [-i <gpon pon id interval>]
Nikolay Titov89004ec2017-06-19 18:22:42 -0400557 [-p <channel partition reference>] [-o <gpon pon id odn class>]
558
559get: displays existing channel pairs
560 Required flags: None
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400561create: creates channel pair with the parameters specified with -n, -d, -a,
562 -l, -r, -t, -g, -i, -p and -o.
Nikolay Titov89004ec2017-06-19 18:22:42 -0400563 Required flags: <name>, <channel pair type>
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400564update: updates existing channel pair specified with parameter -n by changing
565 its parameter values specified with -d, -a, -l, -r, -t, -g, -i, -p
566 and -o.
Nikolay Titov89004ec2017-06-19 18:22:42 -0400567 Required flags: <name>
568delete: deletes channel group specified with parameter -n.
569 Required flags: <name>
570
571-n: <string> name of channel pair.
572-d: <string> description of channel pair.
573-a: <string> admin state of channel pair.
574-l: <enum> link up down trap enable type.
575-r: <string> channel pair line rate.
576-t: <string> channel pair type.
577-g: <string> channel group reference.
578-i: <int> gpon pon id interval.
579-p: <string> channel partition reference.
580-o: <enum> gpon pon id odn class.
581
582Example:
583
Nikolay Titov176f1db2017-08-10 12:38:43 -0400584channel_pair create -n "PON port" -d "Channel Pair for Freedom Tower" -a up
585 -r down_10_up_10 -t channelpair -g "Manhattan"
586 -p "Freedom Tower" -i 0 -o class_a
Nikolay Titov89004ec2017-06-19 18:22:42 -0400587'''
588 )
589
590 @options([
591 make_option('-n', '--name', action="store", dest='name', type='string',
592 help='name of channel pair', default=None),
593 make_option('-d', '--description', action="store", dest='description',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400594 type='string', help='description of channel pair',
595 default=None),
596 make_option('-a', '--admin_state', action="store", dest='enabled',
597 type='string', help='admin state of channel pair',
598 default=None),
599 make_option('-l', '--trap', action="store",
600 dest='link_up_down_trap_enable', type='string',
601 help='link up down trap enable type', default=None),
602 make_option('-r', '--cp_line_rate', action='store',
603 dest='channelpair_linerate', type='string',
604 help='channel pair linerate', default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400605 make_option('-t', '--cp_type', action='store', dest='channelpair_type',
606 type='string', help='channel pair type', default=None),
607 make_option('-g', '--cg_ref', action='store', dest='channelgroup_ref',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400608 type='string', help='channel group reference',
609 default=None),
610 make_option('-i', '--interval', action='store',
611 dest='gpon_ponid_interval', type='int',
612 help='gpon pon id interval', default=None),
613 make_option('-p', '--cpart_ref', action='store',
614 dest='channelpartition_ref', type='string',
615 help='channel partition reference', default=None),
616 make_option('-o', '--odn_class', action='store',
617 dest='gpon_ponid_odn_class', type='string',
618 help='gpon pon id odn class', default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400619 ])
620
621 def do_channel_pair(self, line, opts):
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400622 """channel pair get, create -flags <attributes>,
623 update -flags <attributes>, delete -n <name>"""
Nikolay Titov89004ec2017-06-19 18:22:42 -0400624 # Ensure that a valid sub-command was provided
625 if line.strip() not in {"get", "create", "update", "delete"}:
Nikolay Titov176f1db2017-08-10 12:38:43 -0400626 self.poutput(self.colorize('Error: ', 'red') +
627 self.colorize(self.colorize(line.strip(), 'blue'),
628 'bold') + ' is not recognized')
Nikolay Titov89004ec2017-06-19 18:22:42 -0400629 return
630
Nikolay Titov176f1db2017-08-10 12:38:43 -0400631 stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel())
Nikolay Titov89004ec2017-06-19 18:22:42 -0400632
633 if line.strip() == "get":
634 if self.device_id:
Nikolay Titov176f1db2017-08-10 12:38:43 -0400635 cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400636 self.get_interface_based_on_device()
637 print_pb_list_as_table("Channel Pairs for device ID = {}:"
638 .format(self.device_id), cp, {},
639 self.poutput)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400640 else:
641 interface = stub.GetAllChannelpairConfig(Empty())
642 print_pb_list_as_table("Channel Pairs:",
643 interface.channelpair_config,
644 {}, self.poutput)
645 return
Nikolay Titov176f1db2017-08-10 12:38:43 -0400646 try:
647 interface_instance = ChannelpairConfig(name = opts.name)
648 interface_instance.interface.name = opts.name
649 if opts.description:
650 interface_instance.interface.description = opts.description
651 interface_instance.interface.type = "channelpair"
652 if opts.enabled:
653 if opts.enabled == "up":
654 interface_instance.interface.enabled = True
655 elif opts.enabled == "down":
656 interface_instance.interface.enabled = False
657 else:
658 self.poutput(
659 self.colorize('Error: ', 'red') + self.colorize(
660 self.colorize('Invalid admin state parameter for \
661 channel pair', 'blue'), 'bold'))
662 return
663 if opts.link_up_down_trap_enable:
664 types = ["trap_disabled", "trap_enabled"]
Nikolay Titov89004ec2017-06-19 18:22:42 -0400665 assert opts.link_up_down_trap_enable in types, \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400666 'Invalid Enum value for Channel Pair link up down \
667 trap enable type \'{}\''.format(
668 opts.link_up_down_trap_enable)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400669 interface_instance.interface.link_up_down_trap_enable = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400670 ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\
671 values_by_name[opts.link_up_down_trap_enable.upper()].\
672 number
Nikolay Titov176f1db2017-08-10 12:38:43 -0400673 if opts.channelpair_linerate:
674 interface_instance.data.channelpair_linerate = \
675 opts.channelpair_linerate
676 if opts.channelpair_type:
677 interface_instance.data.channelpair_type = \
678 opts.channelpair_type
679 if opts.channelgroup_ref:
680 interface_instance.data.channelgroup_ref = \
681 opts.channelgroup_ref
682 if opts.gpon_ponid_interval:
683 interface_instance.data.gpon_ponid_interval = \
684 opts.gpon_ponid_interval
685 if opts.channelpartition_ref:
686 interface_instance.data.channelpartition_ref = \
687 opts.channelpartition_ref
688 if opts.gpon_ponid_odn_class:
689 class_types = ["class_a", "class_b", "class_b_plus", "class_c",
690 "class_c_plus", "class_auto"]
Nikolay Titov89004ec2017-06-19 18:22:42 -0400691 assert opts.gpon_ponid_odn_class in class_types, \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400692 'Invalid enum value for Channel Pair gpon pon id odn \
693 class \'{}\''.format(opts.gpon_ponid_odn_class)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400694 interface_instance.data.gpon_ponid_odn_class = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400695 bbf_fiber_types_pb2._PONIDODNCLASSTYPE.\
696 values_by_name[opts.gpon_ponid_odn_class.upper()].number
Nikolay Titov176f1db2017-08-10 12:38:43 -0400697 if line.strip() == "create":
698 stub.CreateChannelpair(interface_instance)
699 elif line.strip() == "update":
700 stub.UpdateChannelpair(interface_instance)
701 elif line.strip() == "delete":
702 stub.DeleteChannelpair(interface_instance)
703 return
704 except Exception, e:
705 self.poutput(
706 self.colorize('Error: ', 'red') +
707 self.colorize(self.colorize(e.message, 'blue'), 'bold'))
708 return
Nikolay Titov89004ec2017-06-19 18:22:42 -0400709
710 def help_channel_termination(self):
711 self.poutput(
712'''
713channel_termination [get | create | update | delete] [-i <id>] [-n <name>]
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400714 [-d <description>] [-a <admin state>]
715 [-l <link up down trap enable type>]
716 [-r <channel pair reference>]
717 [-m <meant for type_b primary role>]
718 [-w <ngpon2 time wavelength division multiplexing
719 admin label>]
Nikolay Titov89004ec2017-06-19 18:22:42 -0400720 [-p <ngpon2 ptp admin label>] [-s <xgs pon id>]
721 [-x <xgpon pon id>] [-g <gpon pon id>] [-t <pon tag>]
722 [-b <ber calc period>] [-l <location>] [-u <url to reach>]
723
724get: displays existing channel pairs
725 Required flags: None
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400726create: creates channel pair with the parameters specified with -i -n, -d, -a,
727 -l, -r, -m, -w, -p, -s, -x, -g, -t, -b, -c and -u
Nikolay Titov89004ec2017-06-19 18:22:42 -0400728 Required flags: <id>, <name>
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400729update: updates existing channel termination specified with -i and -n
730 parameters by changing its parameter values specified with -d, -a, -l,
731 -r, -m, -w, -p, -s, -x, -g, -b, -c, and -u
Nikolay Titov89004ec2017-06-19 18:22:42 -0400732 Required flags: <id>, <name>
733delete: deletes channel termination specified with parameter -i and -n.
734 Required flags: <id>, <name>
735
736-i: <string> device id.
737-n: <string> name of channel termination.
738-d: <string> description of channel termination.
739-a: <string> admin state of channel termination.
740-l: <enum> link up down trap enable type.
741-r: <string> channel pair reference for this channel termination.
742-m: <bool> meant for type_b primary role.
743-w: <int> ngpon2 time wavelength division multiplexing admin label.
744-p: <int> ngpon2 precision time protocol admin label.
745-s: <int> xgs pon id.
746-x: <int> xgpon pon id.
747-g: <string> gpon pon id.
748-t: <string> pon tag.
749-b: <int> bit error rate calculation period.
750-c: <string> location of channel termination.
751-u: <string> url to reach channel termination.
752
753Example:
754
Nikolay Titov176f1db2017-08-10 12:38:43 -0400755channel_termination create -i <DEVICE_ID> -n "PON port"
756 -d "Channel Termination for Freedom Tower" -a up
757 -r "PON port" -c "Freedom Tower OLT"
Nikolay Titov89004ec2017-06-19 18:22:42 -0400758'''
759 )
760
761 @options([
762 make_option('-i', '--id', action="store", dest='id', type='string',
763 help='device id', default=None),
764 make_option('-n', '--name', action="store", dest='name', type='string',
765 help='name of channel pair', default=None),
766 make_option('-d', '--description', action="store", dest='description',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400767 type='string', help='description of channel termination',
768 default=None),
769 make_option('-a', '--admin_state', action="store", dest='enabled',
770 type='string', help='admin state of channel termination',
771 default=None),
772 make_option('-l', '--trap', action="store",
773 dest='link_up_down_trap_enable', type='string',
774 help='link up down trap enable type', default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400775 make_option('-r', '--cp_ref', action='store', dest='channelpair_ref',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400776 type='string',
777 help='channel pair reference for this channel termination',
778 default=None),
779 make_option('-m', '--type_b', action='store',
780 dest='meant_for_type_b_primary_role', type='string',
781 help='meant for type_b primary role', default=None),
782 make_option('-w', '--t_w_d_m', action='store',
783 dest='ngpon2_twdm_admin_label', type='int',
784 help='ngpon2 time wavelength division multiplexing admin \
785 label', default=None),
786 make_option('-p', '--ptp', action='store',
787 dest='ngpon2_ptp_admin_label', type='int',
788 help='ngpon2 precision time protocol admin label',
789 default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400790 make_option('-s', '--xgs', action='store', dest='xgs_ponid',
791 type='int', help='xgs pon id', default=None),
792 make_option('-x', '--xgpon', action='store', dest='xgpon_ponid',
793 type='int', help='xgpon pon id', default=None),
794 make_option('-g', '--gpon_pon', action='store', dest='gpon_ponid',
795 type='string', help='gpon pon id', default=None),
796 make_option('-t', '--pon', action='store', dest='pon_tag',
797 type='string', help='pon tag', default=None),
798 make_option('-b', '--ber', action='store', dest='ber_calc_period',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400799 type='int', help='bit error rate calculation period',
800 default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400801 make_option('-c', '--location', action='store', dest='location',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400802 type='string', help='location of channel termination',
803 default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400804 make_option('-u', '--url', action='store', dest='url_to_reach',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400805 type='string', help='url to reach channel termination',
806 default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400807 ])
808
809 def do_channel_termination(self, line, opts):
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400810 """channel termination get, create -flags <attributes>,
811 update -flags <attributes>, delete -i <id> -n <name>"""
Nikolay Titov89004ec2017-06-19 18:22:42 -0400812 # Ensure that a valid sub-command was provided
813 if line.strip() not in {"get", "create", "update", "delete"}:
Nikolay Titov176f1db2017-08-10 12:38:43 -0400814 self.poutput(self.colorize('Error: ', 'red') +
815 self.colorize(self.colorize(line.strip(), 'blue'),
816 'bold') + ' is not recognized')
Nikolay Titov89004ec2017-06-19 18:22:42 -0400817 return
818
Nikolay Titov176f1db2017-08-10 12:38:43 -0400819 stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel())
Nikolay Titov89004ec2017-06-19 18:22:42 -0400820
821 if line.strip() == "get":
822 if self.device_id:
Nikolay Titov176f1db2017-08-10 12:38:43 -0400823 cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400824 self.get_interface_based_on_device()
825 print_pb_list_as_table(
826 "Channel Terminations for device ID = {}:"
827 .format(self.device_id), ct, {}, self.poutput)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400828 elif opts.id:
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400829 ct = stub.GetAllChannelterminationConfig(
830 voltha_pb2.ID(id=opts.id)).channeltermination_config
831 print_pb_list_as_table(
832 "Channel Terminations for device ID = {}:".format(opts.id),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400833 ct, {}, self.poutput)
834 else:
835 devices = stub.ListDevices(Empty())
836 for d in devices.items:
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400837 interface = stub.GetAllChannelterminationConfig(
838 voltha_pb2.ID(id=d.id))
839 print_pb_list_as_table(
840 "Channel Terminations for device ID = {}:"
841 .format(d.id), interface.channeltermination_config,
842 {}, self.poutput)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400843 return
Nikolay Titov176f1db2017-08-10 12:38:43 -0400844 try:
845 interface_instance = ChannelterminationConfig(
846 id = opts.id, name = opts.name)
847 interface_instance.interface.name = opts.name
848 if opts.description:
849 interface_instance.interface.description = opts.description
850 interface_instance.interface.type = "channel-termination"
851 if opts.enabled:
852 if opts.enabled == "up":
853 interface_instance.interface.enabled = True
854 elif opts.enabled == "down":
855 interface_instance.interface.enabled = False
856 else:
857 self.poutput(
858 self.colorize('Error: ', 'red') + self.colorize(
859 self.colorize('Invalid admin state parameter for \
860 channel termination', 'blue'), 'bold'))
861 return
862 if opts.link_up_down_trap_enable:
863 types = ["trap_disabled", "trap_enabled"]
Nikolay Titov89004ec2017-06-19 18:22:42 -0400864 assert opts.link_up_down_trap_enable in types, \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400865 'Invalid Enum value for Channel Termination link up \
866 down trap enable type \'{}\''.format(
867 opts.link_up_down_trap_enable)
Nikolay Titov89004ec2017-06-19 18:22:42 -0400868 interface_instance.interface.link_up_down_trap_enable = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400869 ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\
870 values_by_name[opts.link_up_down_trap_enable.upper()].\
871 number
Nikolay Titov176f1db2017-08-10 12:38:43 -0400872 if opts.channelpair_ref:
873 interface_instance.data.channelpair_ref = opts.channelpair_ref
874 if opts.meant_for_type_b_primary_role:
875 if opts.meant_for_type_b_primary_role == 'true':
876 interface_instance.data.meant_for_type_b_primary_role = \
877 True
878 elif opts.meant_for_type_b_primary_role == 'false':
879 interface_instance.data.meant_for_type_b_primary_role = \
880 False
881 else:
882 m = 'Invalid boolean value for Channel Termination \
883 meant_for_type_b_primary_role \'{}\''.format(
884 opts.meant_for_type_b_primary_role)
885 self.poutput(
886 self.colorize('Error: ', 'red') +
887 self.colorize(self.colorize(m, 'blue'), 'bold'))
888 return
889 if opts.ngpon2_twdm_admin_label:
890 interface_instance.data.ngpon2_twdm_admin_label = \
891 opts.ngpon2_twdm_admin_label
892 if opts.ngpon2_ptp_admin_label:
893 interface_instance.data.ngpon2_ptp_admin_label = \
894 opts.ngpon2_ptp_admin_label
895 if opts.xgs_ponid:
896 interface_instance.data.xgs_ponid = opts.xgs_ponid
897 if opts.xgpon_ponid:
898 interface_instance.data.xgpon_ponid = opts.xgpon_ponid
899 if opts.gpon_ponid:
900 interface_instance.data.gpon_ponid = opts.gpon_ponid
901 if opts.pon_tag:
902 interface_instance.data.pon_tag = opts.pon_tag
903 if opts.ber_calc_period:
904 interface_instance.data.ber_calc_period = opts.ber_calc_period
905 if opts.location:
906 interface_instance.data.location = opts.location
907 if opts.url_to_reach:
908 interface_instance.data.url_to_reach = opts.url_to_reach
909 if line.strip() == "create":
910 stub.CreateChanneltermination(interface_instance)
911 elif line.strip() == "update":
912 stub.UpdateChanneltermination(interface_instance)
913 elif line.strip() == "delete":
914 stub.DeleteChanneltermination(interface_instance)
915 return
916 except Exception, e:
917 self.poutput(
918 self.colorize('Error: ', 'red') +
919 self.colorize(self.colorize(e.message, 'blue'), 'bold'))
920 return
Nikolay Titov89004ec2017-06-19 18:22:42 -0400921
922 def help_vont_ani(self):
923 self.poutput(
924'''
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400925vont_ani [get | create | update | delete] [-n <name>] [-d <description>]
926 [-a <admin state>] [-l <link up down trap enable type>]
927 [-p <parent reference>] [-s <expected serial number>]
928 [-i <expected registration id>] [-r <preferred channel pair>]
929 [-t <protection channel pair>] [-u <upstream channel speed>]
930 [-o <onu id>]
Nikolay Titov89004ec2017-06-19 18:22:42 -0400931
932get: displays existing vont anis
933 Required flags: None
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400934create: creates vont ani with the parameters specified with -n, -d, -a, -l,
935 -p, -s, -i, -r, -t, -u and -o.
Nikolay Titov89004ec2017-06-19 18:22:42 -0400936 Required flags: <name>
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400937update: updates existing vont ani specified with parameter -n by changing its
938 parameter values specified with -d, -a, -l, -p, -s, -i, -r, -t, -u
939 and -o.
Nikolay Titov89004ec2017-06-19 18:22:42 -0400940 Required flags: <name>
941delete: deletes vont ani specified with parameter -n.
942 Required flags: <name>
943
944-n: <string> name of vont ani.
945-d: <string> description of vont ani.
946-a: <string> admin state of vont ani.
947-l: <enum> link up down trap enable type.
948-p: <string> parent reference of vont ani must be type of channel partition.
949-s: <string> expected serial number of ONT.
950-i: <string> expected registration id of ONT.
951-r: <string> preferred channel pair must be type of channel pair.
952-t: <string> protection channel pair must be type of channel pair.
953-u: <int> upstream channel speed of traffic.
Nikolay Titov176f1db2017-08-10 12:38:43 -0400954-o: <int> ONU id.
Nikolay Titov89004ec2017-06-19 18:22:42 -0400955
956Example:
957
Nikolay Titov176f1db2017-08-10 12:38:43 -0400958vont_ani create -n "Golden User" -d "Golden User in Freedom Tower" -a up
959 -p "Freedom Tower" -s "PSMO00000001" -r "PON port" -o 1
Nikolay Titov89004ec2017-06-19 18:22:42 -0400960'''
961 )
962
963 @options([
964 make_option('-n', '--name', action="store", dest='name', type='string',
965 help='name of vont ani', default=None),
966 make_option('-d', '--description', action="store", dest='description',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400967 type='string', help='description of vont ani',
968 default=None),
969 make_option('-a', '--admin_state', action="store", dest='enabled',
970 type='string', help='admin state of vont ani',
971 default=None),
972 make_option('-l', '--trap', action="store",
973 dest='link_up_down_trap_enable', type='string',
974 help='link up down trap enable type', default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400975 make_option('-p', '--parent_ref', action='store', dest='parent_ref',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400976 type='string',
977 help='parent reference of vont ani must be type of \
978 channel partition', default=None),
979 make_option('-s', '--e_ser_num', action='store',
980 dest='expected_serial_number', type='string',
981 help='expected serial number of ONT', default=None),
982 make_option('-i', '--e_reg_id', action='store',
983 dest='expected_registration_id', type='string',
984 help='expected registration id of ONT', default=None),
985 make_option('-r', '--pref_cp', action='store',
986 dest='preferred_chanpair', type='string',
987 help='preferred channel pair must be type of channel pair',
Nikolay Titov89004ec2017-06-19 18:22:42 -0400988 default=None),
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -0400989 make_option('-t', '--prot_cp', action='store',
990 dest='protection_chanpair', type='string',
991 help='protection channel pair must be type of channel \
992 pair', default=None),
993 make_option('-u', '--up_cs', action='store',
994 dest='upstream_channel_speed', type='int',
995 help='upstream channel speed of traffic', default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -0400996 make_option('-o', '--onu_id', action='store', dest='onu_id',
997 type='int', help='onu id', default=None),
998 ])
999
1000 def do_vont_ani(self, line, opts):
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001001 """vont ani get, create -flags <attributes>,
1002 update -flags <attributes>, delete -n <name>"""
Nikolay Titov89004ec2017-06-19 18:22:42 -04001003 # Ensure that a valid sub-command was provided
1004 if line.strip() not in {"get", "create", "update", "delete"}:
Nikolay Titov176f1db2017-08-10 12:38:43 -04001005 self.poutput(self.colorize('Error: ', 'red') +
1006 self.colorize(self.colorize(line.strip(), 'blue'),
1007 'bold') + ' is not recognized')
Nikolay Titov89004ec2017-06-19 18:22:42 -04001008 return
1009
Nikolay Titov176f1db2017-08-10 12:38:43 -04001010 stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel())
Nikolay Titov89004ec2017-06-19 18:22:42 -04001011
1012 if line.strip() == "get":
1013 if self.device_id:
Nikolay Titov176f1db2017-08-10 12:38:43 -04001014 cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001015 self.get_interface_based_on_device()
1016 print_pb_list_as_table("VOnt Anis for device ID = {}:"
1017 .format(self.device_id), vont, {},
1018 self.poutput)
Nikolay Titov89004ec2017-06-19 18:22:42 -04001019 else:
1020 interface = stub.GetAllVOntaniConfig(Empty())
1021 print_pb_list_as_table("VOnt Anis:",
1022 interface.v_ontani_config,
1023 {}, self.poutput)
1024 return
Nikolay Titov176f1db2017-08-10 12:38:43 -04001025 try:
1026 interface_instance = VOntaniConfig(name = opts.name)
1027 interface_instance.interface.name = opts.name
1028 if opts.description:
1029 interface_instance.interface.description = opts.description
1030 interface_instance.interface.type = "v-ontani"
1031 if opts.enabled:
1032 if opts.enabled == "up":
1033 interface_instance.interface.enabled = True
1034 elif opts.enabled == "down":
1035 interface_instance.interface.enabled = False
1036 else:
1037 self.poutput(
1038 self.colorize('Error: ', 'red') + self.colorize(
1039 self.colorize('Invalid admin state parameter for \
1040 vont ani', 'blue'), 'bold'))
1041 return
1042 if opts.link_up_down_trap_enable:
1043 types = ["trap_disabled", "trap_enabled"]
Nikolay Titov89004ec2017-06-19 18:22:42 -04001044 assert opts.link_up_down_trap_enable in types, \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001045 'Invalid Enum value for VOnt Ani link up down trap \
1046 enable type \'{}\''.format(
1047 opts.link_up_down_trap_enable)
Nikolay Titov89004ec2017-06-19 18:22:42 -04001048 interface_instance.interface.link_up_down_trap_enable = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001049 ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\
1050 values_by_name[opts.link_up_down_trap_enable.upper()].\
1051 number
Nikolay Titov176f1db2017-08-10 12:38:43 -04001052 if opts.parent_ref:
1053 interface_instance.data.parent_ref = opts.parent_ref
1054 if opts.expected_serial_number:
1055 interface_instance.data.expected_serial_number = \
1056 opts.expected_serial_number
1057 if opts.expected_registration_id:
1058 interface_instance.data.expected_registration_id = \
1059 opts.expected_registration_id
1060 if opts.preferred_chanpair:
1061 interface_instance.data.preferred_chanpair = \
1062 opts.preferred_chanpair
1063 if opts.protection_chanpair:
1064 interface_instance.data.protection_chanpair = \
1065 opts.protection_chanpair
1066 if opts.upstream_channel_speed:
1067 interface_instance.data.upstream_channel_speed = \
1068 opts.upstream_channel_speed
1069 if opts.onu_id:
1070 interface_instance.data.onu_id = opts.onu_id
1071 if line.strip() == "create":
1072 stub.CreateVOntani(interface_instance)
1073 elif line.strip() == "update":
1074 stub.UpdateVOntani(interface_instance)
1075 elif line.strip() == "delete":
1076 stub.DeleteVOntani(interface_instance)
1077 return
1078 except Exception, e:
1079 self.poutput(
1080 self.colorize('Error: ', 'red') +
1081 self.colorize(self.colorize(e.message, 'blue'), 'bold'))
1082 return
Nikolay Titov89004ec2017-06-19 18:22:42 -04001083
1084 def help_ont_ani(self):
1085 self.poutput(
1086'''
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001087ont_ani [get | create | update | delete] [-n <name>] [-d <description>]
1088 [-a <admin state>] [-l <link up down trap enable type>]
1089 [-u <upstream fec indicator>] [-m <management gem port aes indicator>]
Nikolay Titov89004ec2017-06-19 18:22:42 -04001090
1091get: displays existing ont anis
1092 Required flags: None
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001093create: creates ont ani with the parameters specified with -n, -d, -a, -l, -u
1094 and -m.
Nikolay Titov89004ec2017-06-19 18:22:42 -04001095 Required flags: <name>
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001096update: updates existing ont ani specified with parameter -n by changing its
1097 parameter values specified with -d, -a, -l, -u and -m.
Nikolay Titov89004ec2017-06-19 18:22:42 -04001098 Required flags: <name>
1099delete: deletes ont ani specified with parameter -n.
1100 Required flags: <name>
1101
1102-n: <string> name of ont ani.
1103-d: <string> description of ont ani.
1104-a: <string> admin state of ont ani.
1105-l: <enum> link up down trap enable type.
1106-u: <bool> upstream traffic fec indicator.
1107-m: <bool> management gem port aes indicator.
1108
1109Example:
1110
Nikolay Titov176f1db2017-08-10 12:38:43 -04001111ont_ani create -n "Golden User" -d "Golden User in Freedom Tower" -a up -u true
1112 -m false
Nikolay Titov89004ec2017-06-19 18:22:42 -04001113'''
1114 )
1115
1116 @options([
1117 make_option('-n', '--name', action="store", dest='name', type='string',
1118 help='name of ont ani', default=None),
1119 make_option('-d', '--description', action="store", dest='description',
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001120 type='string', help='description of ont ani',
1121 default=None),
1122 make_option('-a', '--admin_state', action="store", dest='enabled',
1123 type='string', help='admin state of ont ani',
1124 default=None),
1125 make_option('-l', '--trap', action="store",
1126 dest='link_up_down_trap_enable', type='string',
1127 help='link up down trap enable type', default=None),
1128 make_option('-u', '--up_fec', action='store',
1129 dest='upstream_fec_indicator', type='string',
1130 help='upstream traffic fec indicator', default=None),
1131 make_option('-m', '--maes', action='store',
1132 dest='mgnt_gemport_aes_indicator', type='string',
1133 help='management gem port aes indicator', default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -04001134 ])
1135
1136 def do_ont_ani(self, line, opts):
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001137 """ont ani get, create -flags <attributes>,
1138 update -flags <attributes>, delete -n <name>"""
Nikolay Titov89004ec2017-06-19 18:22:42 -04001139 # Ensure that a valid sub-command was provided
1140 if line.strip() not in {"get", "create", "update", "delete"}:
Nikolay Titov176f1db2017-08-10 12:38:43 -04001141 self.poutput(self.colorize('Error: ', 'red') +
1142 self.colorize(self.colorize(line.strip(), 'blue'),
1143 'bold') + ' is not recognized')
Nikolay Titov89004ec2017-06-19 18:22:42 -04001144 return
1145
Nikolay Titov176f1db2017-08-10 12:38:43 -04001146 stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel())
Nikolay Titov89004ec2017-06-19 18:22:42 -04001147
1148 if line.strip() == "get":
1149 if self.device_id:
Nikolay Titov176f1db2017-08-10 12:38:43 -04001150 cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001151 self.get_interface_based_on_device()
1152 print_pb_list_as_table("Ont Anis for device ID = {}:".format(
1153 self.device_id), ont, {}, self.poutput)
Nikolay Titov89004ec2017-06-19 18:22:42 -04001154 else:
1155 interface = stub.GetAllOntaniConfig(Empty())
1156 print_pb_list_as_table("Ont Anis:",
1157 interface.ontani_config,
1158 {}, self.poutput)
1159 return
Nikolay Titov176f1db2017-08-10 12:38:43 -04001160 try:
1161 interface_instance = OntaniConfig(name = opts.name)
1162 interface_instance.interface.name = opts.name
1163 if opts.description:
1164 interface_instance.interface.description = opts.description
1165 interface_instance.interface.type = "ontani"
1166 if opts.enabled:
1167 if opts.enabled == "up":
1168 interface_instance.interface.enabled = True
1169 elif opts.enabled == "down":
1170 interface_instance.interface.enabled = False
1171 else:
1172 self.poutput(
1173 self.colorize('Error: ', 'red') + self.colorize(
1174 self.colorize(
1175 'Invalid admin state parameter for ont ani',
1176 'blue'), 'bold'))
1177 return
1178 if opts.link_up_down_trap_enable:
1179 types = ["trap_disabled", "trap_enabled"]
Nikolay Titov89004ec2017-06-19 18:22:42 -04001180 assert opts.link_up_down_trap_enable in types, \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001181 'Invalid Enum value for Ont Ani link up down trap \
1182 enable type \'{}\''.format(
1183 opts.link_up_down_trap_enable)
Nikolay Titov89004ec2017-06-19 18:22:42 -04001184 interface_instance.interface.link_up_down_trap_enable = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001185 ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\
1186 values_by_name[opts.link_up_down_trap_enable.upper()].\
1187 number
Nikolay Titov176f1db2017-08-10 12:38:43 -04001188 if opts.upstream_fec_indicator:
1189 if opts.upstream_fec_indicator == 'true':
1190 interface_instance.data.upstream_fec_indicator = True
1191 elif opts.upstream_fec_indicator == 'false':
1192 interface_instance.data.upstream_fec_indicator = False
1193 else:
1194 m = 'Invalid boolean value for Ont Ani \
1195 upstream_fec_indicator \'{}\''.format(
1196 opts.upstream_fec_indicator)
1197 self.poutput(
1198 self.colorize('Error: ', 'red') + self.colorize(
1199 self.colorize(m, 'blue'), 'bold'))
1200 return
1201 if opts.mgnt_gemport_aes_indicator:
1202 if opts.mgnt_gemport_aes_indicator == 'true':
1203 interface_instance.data.mgnt_gemport_aes_indicator = True
1204 elif opts.mgnt_gemport_aes_indicator == 'false':
1205 interface_instance.data.mgnt_gemport_aes_indicator = False
1206 else:
1207 m = 'Invalid boolean value for Ont Ani \
1208 mgnt_gemport_aes_indicator \'{}\''.format(
1209 opts.mgnt_gemport_aes_indicator)
1210 self.poutput(
1211 self.colorize('Error: ', 'red') + self.colorize(
1212 self.colorize(m, 'blue'), 'bold'))
1213 return
1214 if line.strip() == "create":
1215 stub.CreateOntani(interface_instance)
1216 elif line.strip() == "update":
1217 stub.UpdateOntani(interface_instance)
1218 elif line.strip() == "delete":
1219 stub.DeleteOntani(interface_instance)
1220 return
1221 except Exception, e:
1222 self.poutput(
1223 self.colorize('Error: ', 'red') +
1224 self.colorize(self.colorize(e.message, 'blue'), 'bold'))
1225 return
Nikolay Titov89004ec2017-06-19 18:22:42 -04001226
1227 def help_v_enet(self):
1228 self.poutput(
1229'''
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001230v_enet [get | create | update | delete] [-n <name>] [-d <description>]
1231 [-a <admin state>] [-l <link up down trap enable type>]
Nikolay Titov176f1db2017-08-10 12:38:43 -04001232 [-r <vont ani reference>]
Nikolay Titov89004ec2017-06-19 18:22:42 -04001233
1234get: displays existing venets
1235 Required flags: None
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001236create: creates venet with the parameters specified with -n, -d, -a, -l,
1237 and -r.
Nikolay Titov89004ec2017-06-19 18:22:42 -04001238 Required flags: <name>
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001239update: updates existing venet specified with parameter -n by changing its
1240 parameter values specified with -d, -a, -l, -r.
Nikolay Titov89004ec2017-06-19 18:22:42 -04001241 Required flags: <name>
1242delete: deletes venet specified with parameter -n.
1243 Required flags: <name>
1244
1245-n: <string> name of venet.
1246-d: <string> description of venet.
1247-a: <string> admin state of venet.
1248-l: <enum> link up down trap enable type.
Nikolay Titov176f1db2017-08-10 12:38:43 -04001249-r: <string> vont ani reference of this venet.
Nikolay Titov89004ec2017-06-19 18:22:42 -04001250
1251Example:
1252
Nikolay Titov176f1db2017-08-10 12:38:43 -04001253v_enet create -n "Enet UNI 1" -d "Ethernet port - 1" -a up -r "Golden User"
Nikolay Titov89004ec2017-06-19 18:22:42 -04001254'''
1255 )
1256
1257 @options([
1258 make_option('-n', '--name', action="store", dest='name', type='string',
1259 help='name of venet', default=None),
1260 make_option('-d', '--description', action="store", dest='description',
1261 type='string', help='description of venet', default=None),
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001262 make_option('-a', '--admin_state', action="store", dest='enabled',
1263 type='string', help='admin state of venet', default=None),
1264 make_option('-l', '--trap', action="store",
1265 dest='link_up_down_trap_enable', type='string',
1266 help='link up down trap enable type', default=None),
Nikolay Titov176f1db2017-08-10 12:38:43 -04001267 make_option('-r', '--vont_ref', action='store', dest='v_ontani_ref',
1268 type='string', help='vont ani reference', default=None),
Nikolay Titov89004ec2017-06-19 18:22:42 -04001269 ])
1270
1271 def do_v_enet(self, line, opts):
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001272 """v_enet get, create -flags <attributes>,
1273 update -flags <attributes>, delete -n <name>"""
Nikolay Titov89004ec2017-06-19 18:22:42 -04001274 # Ensure that a valid sub-command was provided
1275 if line.strip() not in {"get", "create", "update", "delete"}:
Nikolay Titov176f1db2017-08-10 12:38:43 -04001276 self.poutput(self.colorize('Error: ', 'red') +
1277 self.colorize(self.colorize(line.strip(), 'blue'),
1278 'bold') + ' is not recognized')
Nikolay Titov89004ec2017-06-19 18:22:42 -04001279 return
1280
Nikolay Titov176f1db2017-08-10 12:38:43 -04001281 stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel())
Nikolay Titov89004ec2017-06-19 18:22:42 -04001282
1283 if line.strip() == "get":
1284 if self.device_id:
Nikolay Titov176f1db2017-08-10 12:38:43 -04001285 cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001286 self.get_interface_based_on_device()
Nikolay Titov176f1db2017-08-10 12:38:43 -04001287 print_pb_list_as_table("VEnets for device ID = {}:"
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001288 .format(self.device_id), venet, {},
1289 self.poutput)
Nikolay Titov89004ec2017-06-19 18:22:42 -04001290 else:
1291 interface = stub.GetAllVEnetConfig(Empty())
1292 print_pb_list_as_table("VEnets:",
1293 interface.v_enet_config,
1294 {}, self.poutput)
1295 return
Nikolay Titov176f1db2017-08-10 12:38:43 -04001296 try:
1297 interface_instance = VEnetConfig(name = opts.name)
1298 interface_instance.interface.name = opts.name
1299 if opts.description:
1300 interface_instance.interface.description = opts.description
1301 interface_instance.interface.type = "v-enet"
1302 if opts.enabled:
1303 if opts.enabled == "up":
1304 interface_instance.interface.enabled = True
1305 elif opts.enabled == "down":
1306 interface_instance.interface.enabled = False
1307 else:
1308 self.poutput(
1309 self.colorize('Error: ', 'red') + self.colorize(
1310 self.colorize('Invalid admin state parameter for \
1311 venet', 'blue'), 'bold'))
1312 return
1313 if opts.link_up_down_trap_enable:
1314 types = ["trap_disabled", "trap_enabled"]
Nikolay Titov89004ec2017-06-19 18:22:42 -04001315 assert opts.link_up_down_trap_enable in types, \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001316 'Invalid Enum value for Venet link up down trap \
1317 enable type \'{}\''.format(
1318 opts.link_up_down_trap_enable)
Nikolay Titov89004ec2017-06-19 18:22:42 -04001319 interface_instance.interface.link_up_down_trap_enable = \
Nikolay Titov3f0c9dd2017-07-17 17:37:25 -04001320 ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\
1321 values_by_name[opts.link_up_down_trap_enable.upper()].\
1322 number
Nikolay Titov176f1db2017-08-10 12:38:43 -04001323 if opts.v_ontani_ref:
1324 interface_instance.data.v_ontani_ref = opts.v_ontani_ref
1325 if line.strip() == "create":
1326 stub.CreateVEnet(interface_instance)
1327 elif line.strip() == "update":
1328 stub.UpdateVEnet(interface_instance)
1329 elif line.strip() == "delete":
1330 stub.DeleteVEnet(interface_instance)
1331 return
1332 except Exception, e:
1333 self.poutput(
1334 self.colorize('Error: ', 'red') +
1335 self.colorize(self.colorize(e.message, 'blue'), 'bold'))
1336 return
Nikolay Titov89004ec2017-06-19 18:22:42 -04001337
Nikolay Titov176f1db2017-08-10 12:38:43 -04001338 def help_traffic_descriptor_profile(self):
1339 self.poutput(
1340'''
1341traffic_descriptor_profile [get | create | update | delete]
1342 [-n <name>] [-f <fixed bandwidth>]
1343 [-a <assured bandwidth>] [-m <maximum bandwidth>]
1344 [-p <priority>] [-w <weight>]
1345 [-e <additional bw eligibility indicator>]
Nikolay Titov89004ec2017-06-19 18:22:42 -04001346
Nikolay Titov176f1db2017-08-10 12:38:43 -04001347get: displays existing traffic descriptor profiles
1348 Required flags: None
1349create: creates traffic descriptor profile with the parameters specified with
1350 -n, -f, -a, -p, -w, and -e.
1351 Required flags: <name>, <fixed bandwidth>, <assured bandwidth>,
1352 <maximum bandwidth>
1353update: updates existing traffic descriptor profile specified with parameter -n
1354 by changing its parameter values specified with -f, -a, -p, -w, and -e.
1355 Required flags: <name>
1356delete: deletes traffic descriptor profile specified with parameter -n.
1357 Required flags: <name>
1358
1359-n: <string> name of traffic descriptor profile.
1360-f: <int> fixed bandwidth that represents the reserved portion of the link
1361 capacity that is allocated to the given traffic flow, regardless
1362 of its traffic demand and the overall traffic load conditions.
1363-a: <int> assured bandwidth that represents a portion of the link capacity
1364 that is allocated to the given traffic flow as long as the flow
1365 has unsatisfied traffic demand, regardless of the overall traffic
1366 conditions.
1367-m: <int> maximum bandwidth that represents the upper limit on the total
1368 bandwidth that can be allocated to the traffic flow under any
1369 traffic conditions.
1370-p: <int> priority that is used for scheduling traffic on a TCont.
1371-w: <int> weight that is used for scheduling traffic on a TCont.
1372-e: <enum> additional bandwidth eligibility indicator that in case of
1373 rate-proportional assignment of additional bandwidth, it can be
1374 provisioned to either value (non-assured-sharing,
1375 best-effort-sharing, or none).
1376
1377Example:
1378
1379traffic_descriptor_profile create -n "TDP 1" -f 100000 -a 500000 -m 1000000
1380 -p 1 -w 1
1381 -e additional_bw_eligibility_indicator_none
1382'''
1383 )
1384
1385 @options([
1386 make_option('-n', '--name', action="store", dest='name', type='string',
1387 help='name of traffic descriptor profile', default=None),
1388 make_option('-f', '--fixed_bw', action="store", dest='fixed_bandwidth',
1389 type='int', help='fixed bandwidth of traffic descriptor',
1390 default=None),
1391 make_option('-a', '--assured_bw', action="store",
1392 dest='assured_bandwidth', type='int',
1393 help='assured bandwidth of traffic descriptor',
1394 default=None),
1395 make_option('-m', '--maximum_bw', action="store",
1396 dest='maximum_bandwidth', type='int',
1397 help='maximum bandwidth of traffic descriptor',
1398 default=None),
1399 make_option('-p', '--priority', action='store', dest='priority',
1400 type='int',
1401 help='priority used for scheduling traffic on a TCont',
1402 default=None),
1403 make_option('-w', '--weight', action='store', dest='weight',
1404 type='int',
1405 help='weight used for scheduling traffic on a TCont',
1406 default=None),
1407 make_option('-e', '--add_bw_eligibility_indicator', action='store',
1408 dest='additional_bw_eligibility_indicator', type='string',
1409 help='additional bandwidth eligibility indicator',
1410 default=None),
1411 ])
1412
1413 def do_traffic_descriptor_profile(self, line, opts):
1414 """traffic_descriptor_profile get, create -flags <attributes>,
1415 update -flags <attributes>, delete -n <name>"""
1416 # Ensure that a valid sub-command was provided
1417 if line.strip() not in {"get", "create", "update", "delete"}:
1418 self.poutput(self.colorize('Error: ', 'red') +
1419 self.colorize(self.colorize(line.strip(), 'blue'),
1420 'bold') + ' is not recognized')
1421 return
1422
1423 stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel())
1424
1425 if line.strip() == "get":
1426 if self.device_id:
1427 cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \
1428 self.get_interface_based_on_device()
1429 print_pb_list_as_table(
1430 "Traffic Descriptor Profiles for device ID = {}:"
1431 .format(self.device_id), tdp, {}, self.poutput)
1432 else:
1433 tdp = stub.GetAllTrafficDescriptorProfileData(Empty())
1434 print_pb_list_as_table("Traffic Descriptor Profiles:",
1435 tdp.traffic_descriptor_profiles,
1436 {}, self.poutput)
1437 return
1438 try:
1439 traffic_descriptor = TrafficDescriptorProfileData(name = opts.name)
1440 if opts.fixed_bandwidth:
1441 traffic_descriptor.fixed_bandwidth = opts.fixed_bandwidth
1442 if opts.assured_bandwidth:
1443 traffic_descriptor.assured_bandwidth = opts.assured_bandwidth
1444 if opts.maximum_bandwidth:
1445 traffic_descriptor.maximum_bandwidth = opts.maximum_bandwidth
1446 if opts.priority:
1447 traffic_descriptor.priority = opts.priority
1448 if opts.weight:
1449 traffic_descriptor.weight = opts.weight
1450 if opts.additional_bw_eligibility_indicator:
1451 eligibility_indicator = [
1452 "additional_bw_eligibility_indicator_none",
1453 "additional_bw_eligibility_indicator_best_effort_sharing",
1454 "additional_bw_eligibility_indicator_non_assured_sharing"]
1455 assert opts.additional_bw_eligibility_indicator in \
1456 eligibility_indicator, 'Invalid Enum value for Traffic \
1457 Descriptor Profile additional bandwidth eligibility \
1458 indicator \'{}\''\
1459 .format(opts.additional_bw_eligibility_indicator)
1460 traffic_descriptor.additional_bw_eligibility_indicator = \
1461 bbf_fiber_traffic_descriptor_profile_body_pb2.\
1462 _ADDITIONALBWELIGIBILITYINDICATORTYPE.\
1463 values_by_name\
1464 [opts.additional_bw_eligibility_indicator.upper()].number
1465 if line.strip() == "create":
1466 stub.CreateTrafficDescriptorProfileData(traffic_descriptor)
1467 elif line.strip() == "update":
1468 stub.UpdateTrafficDescriptorProfileData(traffic_descriptor)
1469 elif line.strip() == "delete":
1470 stub.DeleteTrafficDescriptorProfileData(traffic_descriptor)
1471 return
1472 except Exception, e:
1473 self.poutput(
1474 self.colorize('Error: ', 'red') +
1475 self.colorize(self.colorize(e.message, 'blue'), 'bold'))
1476 return
1477
1478 def help_tcont(self):
1479 self.poutput(
1480'''
1481tcont [get | create | update | delete] [-n <name>] [-r <interface reference>]
1482 [-t <traffic descriptor profile reference>]
1483
1484get: displays existing tconts
1485 Required flags: None
1486create: creates tcont with the parameters specified with -n, -r, and -t.
1487 Required flags: <name>, <interface reference>,
1488 <traffic descriptor profile reference>
1489update: updates existing tcont specified with parameter -n by changing its
1490 parameter values specified with -r, -t.
1491 Required flags: <name>
1492delete: deletes tcont specified with parameter -n.
1493 Required flags: <name>
1494
1495-n: <string> name of tcont.
1496-r: <string> reference to vont ani interface.
1497-t: <string> reference to an existing traffic descriptor profile.
1498
1499Example:
1500
1501tcont create -n "TCont 1" -r "Golden User" -t "TDP 1"
1502'''
1503 )
1504
1505 @options([
1506 make_option('-n', '--name', action="store", dest='name', type='string',
1507 help='name of tcont', default=None),
1508 make_option('-r', '--ref', action="store", dest='interface_reference',
1509 type='string', help='reference to vont ani interface',
1510 default=None),
1511 make_option('-t', '--tdp_ref', action="store",
1512 dest='traffic_descriptor_profile_ref', type='string',
1513 help='reference to an existing traffic descriptor profile',
1514 default=None),
1515 ])
1516
1517 def do_tcont(self, line, opts):
1518 """tcont get, create -flags <attributes>,
1519 update -flags <attributes>, delete -n <name>"""
1520 # Ensure that a valid sub-command was provided
1521 if line.strip() not in {"get", "create", "update", "delete"}:
1522 self.poutput(self.colorize('Error: ', 'red') +
1523 self.colorize(self.colorize(line.strip(), 'blue'),
1524 'bold') + ' is not recognized')
1525 return
1526
1527 stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel())
1528
1529 if line.strip() == "get":
1530 if self.device_id:
1531 cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \
1532 self.get_interface_based_on_device()
1533 print_pb_list_as_table("TConts for device ID = {}:".format(
1534 self.device_id), tcont, {}, self.poutput)
1535 else:
1536 tconts = stub.AllTcontsConfigData(Empty())
1537 print_pb_list_as_table(
1538 "TConts:", tconts.tconts_config, {}, self.poutput)
1539 return
1540
1541 try:
1542 tcont = TcontsConfigData(name = opts.name)
1543 if opts.interface_reference:
1544 tcont.interface_reference = opts.interface_reference
1545 if opts.traffic_descriptor_profile_ref:
1546 tcont.traffic_descriptor_profile_ref = \
1547 opts.traffic_descriptor_profile_ref
1548 if line.strip() == "create":
1549 stub.CreateTcontsConfigData(tcont)
1550 elif line.strip() == "update":
1551 stub.UpdateTcontsConfigData(tcont)
1552 elif line.strip() == "delete":
1553 stub.DeleteTcontsConfigData(tcont)
1554 return
1555 except Exception, e:
1556 self.poutput(
1557 self.colorize('Error: ', 'red') +
1558 self.colorize(self.colorize(e.message, 'blue'), 'bold'))
1559 return
1560
1561 def help_gem_port(self):
1562 self.poutput(
1563'''
1564gem_port [get | create | update | delete]
1565 [-n <name>] [-r <interface reference>] [-c <traffic class>]
1566 [-a <aes indicator>] [-t <tcont reference>]
1567
1568get: displays existing gemports
1569 Required flags: None
1570create: creates gemport with the parameters specified with
1571 -n, -r, -c, -a, and -t.
1572 Required flags: <name>, <interface reference>, <traffic class>
1573update: updates existing gemport specified with parameter -n
1574 by changing its parameter values specified with -r, -c, -a, and -t.
1575 Required flags: <name>
1576delete: deletes gemport specified with parameter -n.
1577 Required flags: <name>
1578
1579-n: <string> name of gemport.
1580-r: <string> reference to v_enet interface.
1581-c: <int> traffic class value for gemport.
1582-a: <bool> aes indicator that is used to designate whether AES should be
1583 enabled/disabled for all bi-directional GEM ports associated with
1584 this ONT.
1585-t: <string> tcont reference that is for the purpose of upstream scheduling in
1586 the ONU, a gemport needs to refer to the tcont into which it feeds
1587 upstream traffic.
1588
1589Example:
1590
1591gem_port create -n "GEMPORT 1" -r "Enet UNI 1" -c 0 -a true -t "TCont 1"
1592'''
1593 )
1594
1595 @options([
1596 make_option('-n', '--name', action="store", dest='name', type='string',
1597 help='name of gemport', default=None),
1598 make_option('-r', '--itf_ref', action="store", dest='itf_ref',
1599 type='string', help='reference to v_enet interface',
1600 default=None),
1601 make_option('-c', '--traffic_class', action="store",
1602 dest='traffic_class', type='int',
1603 help='traffic class value for gemport', default=None),
1604 make_option('-a', '--aes_indicator', action="store",
1605 dest='aes_indicator', type='string',
1606 help='aes indicator to designate if AES enabled/disabled',
1607 default=None),
1608 make_option('-t', '--tcont_ref', action='store', dest='tcont_ref',
1609 type='string',
1610 help='tcont reference for purpose of us scheduling in ONU',
1611 default=None),
1612 ])
1613
1614 def do_gem_port(self, line, opts):
1615 """gem_port get, create -flags <attributes>,
1616 update -flags <attributes>, delete -n <name>"""
1617 # Ensure that a valid sub-command was provided
1618 if line.strip() not in {"get", "create", "update", "delete"}:
1619 self.poutput(self.colorize('Error: ', 'red') +
1620 self.colorize(self.colorize(line.strip(), 'blue'),
1621 'bold') + ' is not recognized')
1622 return
1623
1624 stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel())
1625
1626 if line.strip() == "get":
1627 if self.device_id:
1628 cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \
1629 self.get_interface_based_on_device()
1630 print_pb_list_as_table(
1631 "Gem Ports for device ID = {}:"
1632 .format(self.device_id), gemport, {}, self.poutput)
1633 else:
1634 gemport = stub.GetAllGemportsConfigData(Empty())
1635 print_pb_list_as_table("Gem Ports:",
1636 gemport.gemports_config,
1637 {}, self.poutput)
1638 return
1639 try:
1640 gemport = GemportsConfigData(name = opts.name)
1641 if opts.itf_ref:
1642 gemport.itf_ref = opts.itf_ref
1643 if opts.traffic_class:
1644 gemport.traffic_class = opts.traffic_class
1645 if opts.aes_indicator:
1646 if opts.aes_indicator == 'true':
1647 gemport.aes_indicator = True
1648 elif opts.aes_indicator == 'false':
1649 gemport.aes_indicator = False
1650 else:
1651 m = 'Invalid boolean value for Gem Port \
1652 aes_indicator \'{}\''.format(opts.aes_indicator)
1653 self.poutput(
1654 self.colorize('Error: ', 'red') + self.colorize(
1655 self.colorize(m, 'blue'), 'bold'))
1656 return
1657 if opts.tcont_ref:
1658 gemport.tcont_ref = opts.tcont_ref
1659 if line.strip() == "create":
1660 stub.CreateGemportsConfigData(gemport)
1661 elif line.strip() == "update":
1662 stub.UpdateGemportsConfigData(gemport)
1663 elif line.strip() == "delete":
1664 stub.DeleteGemportsConfigData(gemport)
1665 return
1666 except Exception, e:
1667 self.poutput(
1668 self.colorize('Error: ', 'red') +
1669 self.colorize(self.colorize(e.message, 'blue'), 'bold'))
1670 return