Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright 2016 the original author or authors. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | |
| 18 | """ |
| 19 | XPon level CLI commands |
| 20 | """ |
| 21 | from optparse import make_option |
| 22 | from cmd2 import Cmd, options |
| 23 | from simplejson import dumps |
| 24 | |
| 25 | from google.protobuf.empty_pb2 import Empty |
| 26 | from cli.table import print_pb_as_table, print_pb_list_as_table |
| 27 | from cli.utils import print_flows, pb2dict |
| 28 | from voltha.protos import third_party |
| 29 | from voltha.protos.bbf_fiber_base_pb2 import \ |
| 30 | AllChannelgroupConfig, ChannelgroupConfig, \ |
| 31 | AllChannelpairConfig, ChannelpairConfig, \ |
| 32 | AllChannelpartitionConfig, ChannelpartitionConfig, \ |
| 33 | AllChannelterminationConfig, ChannelterminationConfig, \ |
| 34 | AllOntaniConfig, OntaniConfig, AllVOntaniConfig , \ |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 35 | VOntaniConfig, AllVEnetConfig , VEnetConfig, \ |
| 36 | AllTrafficDescriptorProfileData, AllTcontsConfigData, AllGemportsConfigData |
| 37 | from voltha.protos.bbf_fiber_traffic_descriptor_profile_body_pb2 import \ |
| 38 | TrafficDescriptorProfileData |
| 39 | from voltha.protos.bbf_fiber_tcont_body_pb2 import TcontsConfigData |
| 40 | from voltha.protos.bbf_fiber_gemport_body_pb2 import GemportsConfigData |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 41 | |
| 42 | _ = third_party |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 43 | from voltha.protos import voltha_pb2, bbf_fiber_types_pb2, \ |
| 44 | ietf_interfaces_pb2, bbf_fiber_traffic_descriptor_profile_body_pb2 |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 45 | import sys |
| 46 | from 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 | |
| 52 | class 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 59 | self.colorize('voltha-xpon {}'.format(device_id), 'green'), |
| 60 | 'bold') + ') ' |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 61 | |
| 62 | def cmdloop(self): |
| 63 | self._cmdloop() |
| 64 | |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 65 | def get_ref_interfaces(self, all_interfaces, ref_interfaces): |
| 66 | interface_list = [] |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 67 | interface_name_list = [] |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 68 | if not all_interfaces: |
| 69 | return interface_list |
| 70 | if isinstance(all_interfaces[0], (ChannelgroupConfig, |
| 71 | ChannelpartitionConfig, |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 72 | ChannelpairConfig, OntaniConfig, |
| 73 | TrafficDescriptorProfileData)): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 74 | for interface in all_interfaces: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 75 | if interface.name in ref_interfaces and \ |
| 76 | interface.name not in interface_name_list: |
| 77 | interface_name_list.append(interface.name) |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 78 | interface_list.append(interface) |
| 79 | elif isinstance(all_interfaces[0], VOntaniConfig): |
| 80 | for interface in all_interfaces: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 81 | 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 84 | interface_list.append(interface) |
| 85 | elif isinstance(all_interfaces[0], VEnetConfig): |
| 86 | for interface in all_interfaces: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 87 | 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 102 | interface_list.append(interface) |
| 103 | return interface_list |
| 104 | |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 105 | def get_interface_based_on_device(self): |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 106 | 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 115 | 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 Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 133 | 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 143 | return channel_groups, channel_partitions, channel_pairs,\ |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 144 | channel_terminations, vont_anis, ont_anis, venets, \ |
| 145 | traffic_descriptor_profiles, tconts, gemports |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 146 | |
| 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 153 | """Show detailed information of each interface based on device ID |
| 154 | or all interfaces""" |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 155 | stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel()) |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 156 | device_id = self.device_id |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 157 | if line.strip(): |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 158 | self.device_id = line.strip() |
| 159 | if self.device_id: |
| 160 | cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 161 | self.get_interface_based_on_device() |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 162 | print_pb_list_as_table("Channel Groups for device ID = {}:".format( |
| 163 | self.device_id), cg, {}, self.poutput) |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 164 | print_pb_list_as_table("Channel Partitions for device ID = {}:" |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 165 | .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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 169 | print_pb_list_as_table("Channel Terminations for device ID = {}:" |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 170 | .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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 186 | else: |
| 187 | interface = stub.GetAllChannelgroupConfig(Empty()) |
| 188 | print_pb_list_as_table("Channel Groups:", |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 189 | interface.channelgroup_config, {}, |
| 190 | self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 191 | interface = stub.GetAllChannelpartitionConfig(Empty()) |
| 192 | print_pb_list_as_table("Channel Partitions:", |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 193 | interface.channelpartition_config, {}, |
| 194 | self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 195 | interface = stub.GetAllChannelpairConfig(Empty()) |
| 196 | print_pb_list_as_table("Channel Pairs:", |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 197 | interface.channelpair_config, {}, |
| 198 | self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 199 | devices = stub.ListDevices(Empty()) |
| 200 | for d in devices.items: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 201 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 207 | interface = stub.GetAllVOntaniConfig(Empty()) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 208 | print_pb_list_as_table("VOnt Anis:", interface.v_ontani_config, {}, |
| 209 | self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 210 | interface = stub.GetAllOntaniConfig(Empty()) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 211 | print_pb_list_as_table("Ont Anis:", interface.ontani_config, {}, |
| 212 | self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 213 | interface = stub.GetAllVEnetConfig(Empty()) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 214 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 228 | |
| 229 | def help_channel_group(self): |
| 230 | self.poutput( |
| 231 | ''' |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 232 | channel_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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 235 | |
| 236 | get: displays existing channel groups |
| 237 | Required flags: None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 238 | create: creates channel group with the parameters specified with -n, -d, -a, |
| 239 | -l, -p, -s and -r. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 240 | Required flags: <name> |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 241 | update: updates existing channel group specified with parameter -n by changing |
| 242 | its parameter values specified with -d, -a, -l, -p, -s and -r. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 243 | Required flags: <name> |
| 244 | delete: 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 250 | -l: <enum> link up down trap enable type. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 251 | -p: <int> polling period for channel group. |
| 252 | -s: <string> system id for channel group. |
| 253 | -r: <enum> raman mitigation for channel group. |
| 254 | |
| 255 | Example: |
| 256 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 257 | channel_group create -n "Manhattan" -d "Channel Group for Manhattan" -a up |
| 258 | -p 100 -s 000000 -r raman_none |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 259 | ''' |
| 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 266 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 274 | make_option('-p', '--pp', action='store', dest='polling_period', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 275 | type='int', help='polling period of channel group', |
| 276 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 277 | make_option('-s', '--sid', action='store', dest='system_id', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 278 | type='string', help='system id of channel group', |
| 279 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 280 | make_option('-r', '--rm', action='store', dest='raman_mitigation', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 281 | type='string', help='raman mitigation of channel group', |
| 282 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 283 | ]) |
| 284 | |
| 285 | def do_channel_group(self, line, opts): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 286 | """channel group get, create -flags <attributes>, |
| 287 | update -flags <attributes>, delete -n <name>""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 288 | # Ensure that a valid sub-command was provided |
| 289 | if line.strip() not in {"get", "create", "update", "delete"}: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 290 | self.poutput(self.colorize('Error: ', 'red') + |
| 291 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 292 | 'bold') + ' is not recognized') |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 293 | return |
| 294 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 295 | stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel()) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 296 | |
| 297 | if line.strip() == "get": |
| 298 | if self.device_id: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 299 | cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 300 | self.get_interface_based_on_device() |
| 301 | print_pb_list_as_table("Channel Groups for device ID = {}:" |
| 302 | .format(self.device_id), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 303 | 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 Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 310 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 329 | assert opts.link_up_down_trap_enable in types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 330 | 'Invalid Enum value for Channel Group link up down trap \ |
| 331 | enable type \'{}\''.format(opts.link_up_down_trap_enable) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 332 | interface_instance.interface.link_up_down_trap_enable = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 333 | ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\ |
| 334 | values_by_name[opts.link_up_down_trap_enable.upper()]\ |
| 335 | .number |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 336 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 341 | assert opts.raman_mitigation in raman_mitigations, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 342 | 'Invalid Enum value for Channel Group raman mitigation\ |
| 343 | \'{}\''.format(opts.raman_mitigation) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 344 | interface_instance.data.raman_mitigation = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 345 | bbf_fiber_types_pb2._RAMANMITIGATIONTYPE.\ |
| 346 | values_by_name[opts.raman_mitigation.upper()].number |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 347 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 361 | |
| 362 | def help_channel_partition(self): |
| 363 | self.poutput( |
| 364 | ''' |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 365 | channel_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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 372 | |
| 373 | get: displays existing channel partitions |
| 374 | Required flags: None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 375 | create: creates channel partition with the parameters specified with -n, -d, |
| 376 | -a, -l, -r, -o, -f, -m, -u and -c. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 377 | Required flags: <name>, <channel group reference> |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 378 | update: 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 381 | Required flags: <name> |
| 382 | delete: 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 | |
| 396 | Example: |
| 397 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 398 | channel_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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 402 | ''' |
| 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 409 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 423 | make_option('-f', '--fec_ds', action='store', dest='fec_downstream', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 424 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 434 | make_option('-c', '--cg_ref', action='store', dest='channelgroup_ref', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 435 | type='string', |
| 436 | help='channel group reference for this channel partition', |
| 437 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 438 | ]) |
| 439 | |
| 440 | def do_channel_partition(self, line, opts): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 441 | """channel partition get, create -flags <attributes>, |
| 442 | update -flags <attributes>, delete -n <name>""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 443 | # Ensure that a valid sub-command was provided |
| 444 | if line.strip() not in {"get", "create", "update", "delete"}: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 445 | self.poutput(self.colorize('Error: ', 'red') + |
| 446 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 447 | 'bold') + ' is not recognized') |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 448 | return |
| 449 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 450 | stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel()) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 451 | |
| 452 | if line.strip() == "get": |
| 453 | if self.device_id: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 454 | cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 455 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 459 | else: |
| 460 | interface = stub.GetAllChannelpartitionConfig(Empty()) |
| 461 | print_pb_list_as_table("Channel Partitions:", |
| 462 | interface.channelpartition_config, |
| 463 | {}, self.poutput) |
| 464 | return |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 465 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 484 | assert opts.link_up_down_trap_enable in types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 485 | 'Invalid Enum value for Channel Partition link up \ |
| 486 | down trap enable type \'{}\''\ |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 487 | .format(opts.link_up_down_trap_enable) |
| 488 | interface_instance.interface.link_up_down_trap_enable = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 489 | ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\ |
| 490 | values_by_name[opts.link_up_down_trap_enable.upper()].\ |
| 491 | number |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 492 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 527 | assert opts.authentication_method in auth_method_types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 528 | 'Invalid Enum value for Channel Partition \ |
| 529 | authentication method \'{}\''.format( |
| 530 | opts.authentication_method) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 531 | interface_instance.data.authentication_method = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 532 | bbf_fiber_types_pb2._AUTHMETHODTYPE.\ |
| 533 | values_by_name[opts.authentication_method.upper()].number |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 534 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 549 | |
| 550 | def help_channel_pair(self): |
| 551 | self.poutput( |
| 552 | ''' |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 553 | channel_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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 557 | [-p <channel partition reference>] [-o <gpon pon id odn class>] |
| 558 | |
| 559 | get: displays existing channel pairs |
| 560 | Required flags: None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 561 | create: creates channel pair with the parameters specified with -n, -d, -a, |
| 562 | -l, -r, -t, -g, -i, -p and -o. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 563 | Required flags: <name>, <channel pair type> |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 564 | update: 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 567 | Required flags: <name> |
| 568 | delete: 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 | |
| 582 | Example: |
| 583 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 584 | channel_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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 587 | ''' |
| 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 594 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 605 | 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 608 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 619 | ]) |
| 620 | |
| 621 | def do_channel_pair(self, line, opts): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 622 | """channel pair get, create -flags <attributes>, |
| 623 | update -flags <attributes>, delete -n <name>""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 624 | # Ensure that a valid sub-command was provided |
| 625 | if line.strip() not in {"get", "create", "update", "delete"}: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 626 | self.poutput(self.colorize('Error: ', 'red') + |
| 627 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 628 | 'bold') + ' is not recognized') |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 629 | return |
| 630 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 631 | stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel()) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 632 | |
| 633 | if line.strip() == "get": |
| 634 | if self.device_id: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 635 | cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 636 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 640 | else: |
| 641 | interface = stub.GetAllChannelpairConfig(Empty()) |
| 642 | print_pb_list_as_table("Channel Pairs:", |
| 643 | interface.channelpair_config, |
| 644 | {}, self.poutput) |
| 645 | return |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 646 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 665 | assert opts.link_up_down_trap_enable in types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 666 | 'Invalid Enum value for Channel Pair link up down \ |
| 667 | trap enable type \'{}\''.format( |
| 668 | opts.link_up_down_trap_enable) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 669 | interface_instance.interface.link_up_down_trap_enable = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 670 | ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\ |
| 671 | values_by_name[opts.link_up_down_trap_enable.upper()].\ |
| 672 | number |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 673 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 691 | assert opts.gpon_ponid_odn_class in class_types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 692 | 'Invalid enum value for Channel Pair gpon pon id odn \ |
| 693 | class \'{}\''.format(opts.gpon_ponid_odn_class) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 694 | interface_instance.data.gpon_ponid_odn_class = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 695 | bbf_fiber_types_pb2._PONIDODNCLASSTYPE.\ |
| 696 | values_by_name[opts.gpon_ponid_odn_class.upper()].number |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 697 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 709 | |
| 710 | def help_channel_termination(self): |
| 711 | self.poutput( |
| 712 | ''' |
| 713 | channel_termination [get | create | update | delete] [-i <id>] [-n <name>] |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 714 | [-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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 720 | [-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 | |
| 724 | get: displays existing channel pairs |
| 725 | Required flags: None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 726 | create: 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 728 | Required flags: <id>, <name> |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 729 | update: 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 732 | Required flags: <id>, <name> |
| 733 | delete: 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 | |
| 753 | Example: |
| 754 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 755 | channel_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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 758 | ''' |
| 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 767 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 775 | make_option('-r', '--cp_ref', action='store', dest='channelpair_ref', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 776 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 790 | 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 799 | type='int', help='bit error rate calculation period', |
| 800 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 801 | make_option('-c', '--location', action='store', dest='location', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 802 | type='string', help='location of channel termination', |
| 803 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 804 | make_option('-u', '--url', action='store', dest='url_to_reach', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 805 | type='string', help='url to reach channel termination', |
| 806 | default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 807 | ]) |
| 808 | |
| 809 | def do_channel_termination(self, line, opts): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 810 | """channel termination get, create -flags <attributes>, |
| 811 | update -flags <attributes>, delete -i <id> -n <name>""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 812 | # Ensure that a valid sub-command was provided |
| 813 | if line.strip() not in {"get", "create", "update", "delete"}: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 814 | self.poutput(self.colorize('Error: ', 'red') + |
| 815 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 816 | 'bold') + ' is not recognized') |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 817 | return |
| 818 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 819 | stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel()) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 820 | |
| 821 | if line.strip() == "get": |
| 822 | if self.device_id: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 823 | cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 824 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 828 | elif opts.id: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 829 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 833 | ct, {}, self.poutput) |
| 834 | else: |
| 835 | devices = stub.ListDevices(Empty()) |
| 836 | for d in devices.items: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 837 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 843 | return |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 844 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 864 | assert opts.link_up_down_trap_enable in types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 865 | 'Invalid Enum value for Channel Termination link up \ |
| 866 | down trap enable type \'{}\''.format( |
| 867 | opts.link_up_down_trap_enable) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 868 | interface_instance.interface.link_up_down_trap_enable = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 869 | ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\ |
| 870 | values_by_name[opts.link_up_down_trap_enable.upper()].\ |
| 871 | number |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 872 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 921 | |
| 922 | def help_vont_ani(self): |
| 923 | self.poutput( |
| 924 | ''' |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 925 | vont_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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 931 | |
| 932 | get: displays existing vont anis |
| 933 | Required flags: None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 934 | create: creates vont ani with the parameters specified with -n, -d, -a, -l, |
| 935 | -p, -s, -i, -r, -t, -u and -o. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 936 | Required flags: <name> |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 937 | update: 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 940 | Required flags: <name> |
| 941 | delete: 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 Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 954 | -o: <int> ONU id. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 955 | |
| 956 | Example: |
| 957 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 958 | vont_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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 960 | ''' |
| 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 967 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 975 | make_option('-p', '--parent_ref', action='store', dest='parent_ref', |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 976 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 988 | default=None), |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 989 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 996 | 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1001 | """vont ani get, create -flags <attributes>, |
| 1002 | update -flags <attributes>, delete -n <name>""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1003 | # Ensure that a valid sub-command was provided |
| 1004 | if line.strip() not in {"get", "create", "update", "delete"}: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1005 | self.poutput(self.colorize('Error: ', 'red') + |
| 1006 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 1007 | 'bold') + ' is not recognized') |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1008 | return |
| 1009 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1010 | stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel()) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1011 | |
| 1012 | if line.strip() == "get": |
| 1013 | if self.device_id: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1014 | cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1015 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1019 | 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 Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1025 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1044 | assert opts.link_up_down_trap_enable in types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1045 | 'Invalid Enum value for VOnt Ani link up down trap \ |
| 1046 | enable type \'{}\''.format( |
| 1047 | opts.link_up_down_trap_enable) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1048 | interface_instance.interface.link_up_down_trap_enable = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1049 | ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\ |
| 1050 | values_by_name[opts.link_up_down_trap_enable.upper()].\ |
| 1051 | number |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1052 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1083 | |
| 1084 | def help_ont_ani(self): |
| 1085 | self.poutput( |
| 1086 | ''' |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1087 | ont_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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1090 | |
| 1091 | get: displays existing ont anis |
| 1092 | Required flags: None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1093 | create: creates ont ani with the parameters specified with -n, -d, -a, -l, -u |
| 1094 | and -m. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1095 | Required flags: <name> |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1096 | update: updates existing ont ani specified with parameter -n by changing its |
| 1097 | parameter values specified with -d, -a, -l, -u and -m. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1098 | Required flags: <name> |
| 1099 | delete: 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 | |
| 1109 | Example: |
| 1110 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1111 | ont_ani create -n "Golden User" -d "Golden User in Freedom Tower" -a up -u true |
| 1112 | -m false |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1113 | ''' |
| 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1120 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1134 | ]) |
| 1135 | |
| 1136 | def do_ont_ani(self, line, opts): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1137 | """ont ani get, create -flags <attributes>, |
| 1138 | update -flags <attributes>, delete -n <name>""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1139 | # Ensure that a valid sub-command was provided |
| 1140 | if line.strip() not in {"get", "create", "update", "delete"}: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1141 | self.poutput(self.colorize('Error: ', 'red') + |
| 1142 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 1143 | 'bold') + ' is not recognized') |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1144 | return |
| 1145 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1146 | stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel()) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1147 | |
| 1148 | if line.strip() == "get": |
| 1149 | if self.device_id: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1150 | cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1151 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1154 | else: |
| 1155 | interface = stub.GetAllOntaniConfig(Empty()) |
| 1156 | print_pb_list_as_table("Ont Anis:", |
| 1157 | interface.ontani_config, |
| 1158 | {}, self.poutput) |
| 1159 | return |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1160 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1180 | assert opts.link_up_down_trap_enable in types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1181 | 'Invalid Enum value for Ont Ani link up down trap \ |
| 1182 | enable type \'{}\''.format( |
| 1183 | opts.link_up_down_trap_enable) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1184 | interface_instance.interface.link_up_down_trap_enable = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1185 | ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\ |
| 1186 | values_by_name[opts.link_up_down_trap_enable.upper()].\ |
| 1187 | number |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1188 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1226 | |
| 1227 | def help_v_enet(self): |
| 1228 | self.poutput( |
| 1229 | ''' |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1230 | v_enet [get | create | update | delete] [-n <name>] [-d <description>] |
| 1231 | [-a <admin state>] [-l <link up down trap enable type>] |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1232 | [-r <vont ani reference>] |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1233 | |
| 1234 | get: displays existing venets |
| 1235 | Required flags: None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1236 | create: creates venet with the parameters specified with -n, -d, -a, -l, |
| 1237 | and -r. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1238 | Required flags: <name> |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1239 | update: updates existing venet specified with parameter -n by changing its |
| 1240 | parameter values specified with -d, -a, -l, -r. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1241 | Required flags: <name> |
| 1242 | delete: 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 Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1249 | -r: <string> vont ani reference of this venet. |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1250 | |
| 1251 | Example: |
| 1252 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1253 | v_enet create -n "Enet UNI 1" -d "Ethernet port - 1" -a up -r "Golden User" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1254 | ''' |
| 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 Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1262 | 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 Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1267 | make_option('-r', '--vont_ref', action='store', dest='v_ontani_ref', |
| 1268 | type='string', help='vont ani reference', default=None), |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1269 | ]) |
| 1270 | |
| 1271 | def do_v_enet(self, line, opts): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1272 | """v_enet get, create -flags <attributes>, |
| 1273 | update -flags <attributes>, delete -n <name>""" |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1274 | # Ensure that a valid sub-command was provided |
| 1275 | if line.strip() not in {"get", "create", "update", "delete"}: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1276 | self.poutput(self.colorize('Error: ', 'red') + |
| 1277 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 1278 | 'bold') + ' is not recognized') |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1279 | return |
| 1280 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1281 | stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel()) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1282 | |
| 1283 | if line.strip() == "get": |
| 1284 | if self.device_id: |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1285 | cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1286 | self.get_interface_based_on_device() |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1287 | print_pb_list_as_table("VEnets for device ID = {}:" |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1288 | .format(self.device_id), venet, {}, |
| 1289 | self.poutput) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1290 | else: |
| 1291 | interface = stub.GetAllVEnetConfig(Empty()) |
| 1292 | print_pb_list_as_table("VEnets:", |
| 1293 | interface.v_enet_config, |
| 1294 | {}, self.poutput) |
| 1295 | return |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1296 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1315 | assert opts.link_up_down_trap_enable in types, \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1316 | 'Invalid Enum value for Venet link up down trap \ |
| 1317 | enable type \'{}\''.format( |
| 1318 | opts.link_up_down_trap_enable) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1319 | interface_instance.interface.link_up_down_trap_enable = \ |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 1320 | ietf_interfaces_pb2._INTERFACE_LINKUPDOWNTRAPENABLETYPE.\ |
| 1321 | values_by_name[opts.link_up_down_trap_enable.upper()].\ |
| 1322 | number |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1323 | 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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1337 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1338 | def help_traffic_descriptor_profile(self): |
| 1339 | self.poutput( |
| 1340 | ''' |
| 1341 | traffic_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 Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1346 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1347 | get: displays existing traffic descriptor profiles |
| 1348 | Required flags: None |
| 1349 | create: 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> |
| 1353 | update: 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> |
| 1356 | delete: 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 | |
| 1377 | Example: |
| 1378 | |
| 1379 | traffic_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 | ''' |
| 1481 | tcont [get | create | update | delete] [-n <name>] [-r <interface reference>] |
Chip Boling | 97bef1e | 2017-08-29 11:44:28 -0500 | [diff] [blame] | 1482 | [-t <traffic descriptor profile reference>] [-a alloc-id ] |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1483 | |
| 1484 | get: displays existing tconts |
| 1485 | Required flags: None |
| 1486 | create: creates tcont with the parameters specified with -n, -r, and -t. |
| 1487 | Required flags: <name>, <interface reference>, |
| 1488 | <traffic descriptor profile reference> |
| 1489 | update: updates existing tcont specified with parameter -n by changing its |
| 1490 | parameter values specified with -r, -t. |
| 1491 | Required flags: <name> |
| 1492 | delete: 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. |
Chip Boling | 97bef1e | 2017-08-29 11:44:28 -0500 | [diff] [blame] | 1498 | -a: <int> allocation ID (alloc-id) for the TCONT. If not provided, xPON |
| 1499 | Manager will provide the alloc-id for the TCONT. |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1500 | |
| 1501 | Example: |
| 1502 | |
Chip Boling | 97bef1e | 2017-08-29 11:44:28 -0500 | [diff] [blame] | 1503 | tcont create -n "TCont 1" -r "Golden User" -t "TDP 1" -a 1024 |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1504 | ''' |
| 1505 | ) |
| 1506 | |
| 1507 | @options([ |
| 1508 | make_option('-n', '--name', action="store", dest='name', type='string', |
| 1509 | help='name of tcont', default=None), |
| 1510 | make_option('-r', '--ref', action="store", dest='interface_reference', |
| 1511 | type='string', help='reference to vont ani interface', |
| 1512 | default=None), |
| 1513 | make_option('-t', '--tdp_ref', action="store", |
| 1514 | dest='traffic_descriptor_profile_ref', type='string', |
| 1515 | help='reference to an existing traffic descriptor profile', |
| 1516 | default=None), |
Chip Boling | 97bef1e | 2017-08-29 11:44:28 -0500 | [diff] [blame] | 1517 | make_option('-a', '--alloc_id', action='store', dest='alloc_id', |
| 1518 | type='int', help='alloc-id', default=None), |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1519 | ]) |
| 1520 | |
| 1521 | def do_tcont(self, line, opts): |
| 1522 | """tcont get, create -flags <attributes>, |
| 1523 | update -flags <attributes>, delete -n <name>""" |
| 1524 | # Ensure that a valid sub-command was provided |
| 1525 | if line.strip() not in {"get", "create", "update", "delete"}: |
| 1526 | self.poutput(self.colorize('Error: ', 'red') + |
| 1527 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 1528 | 'bold') + ' is not recognized') |
| 1529 | return |
| 1530 | |
| 1531 | stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel()) |
| 1532 | |
| 1533 | if line.strip() == "get": |
| 1534 | if self.device_id: |
| 1535 | cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \ |
| 1536 | self.get_interface_based_on_device() |
| 1537 | print_pb_list_as_table("TConts for device ID = {}:".format( |
| 1538 | self.device_id), tcont, {}, self.poutput) |
| 1539 | else: |
Jonathan Hart | 3be3524 | 2018-02-06 18:24:45 -0800 | [diff] [blame] | 1540 | tconts = stub.GetAllTcontsConfigData(Empty()) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1541 | print_pb_list_as_table( |
| 1542 | "TConts:", tconts.tconts_config, {}, self.poutput) |
| 1543 | return |
| 1544 | |
| 1545 | try: |
| 1546 | tcont = TcontsConfigData(name = opts.name) |
| 1547 | if opts.interface_reference: |
| 1548 | tcont.interface_reference = opts.interface_reference |
| 1549 | if opts.traffic_descriptor_profile_ref: |
| 1550 | tcont.traffic_descriptor_profile_ref = \ |
| 1551 | opts.traffic_descriptor_profile_ref |
Chip Boling | 97bef1e | 2017-08-29 11:44:28 -0500 | [diff] [blame] | 1552 | if opts.alloc_id: |
| 1553 | tcont.alloc_id = opts.alloc_id |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1554 | if line.strip() == "create": |
| 1555 | stub.CreateTcontsConfigData(tcont) |
| 1556 | elif line.strip() == "update": |
| 1557 | stub.UpdateTcontsConfigData(tcont) |
| 1558 | elif line.strip() == "delete": |
| 1559 | stub.DeleteTcontsConfigData(tcont) |
| 1560 | return |
| 1561 | except Exception, e: |
| 1562 | self.poutput( |
| 1563 | self.colorize('Error: ', 'red') + |
| 1564 | self.colorize(self.colorize(e.message, 'blue'), 'bold')) |
| 1565 | return |
| 1566 | |
| 1567 | def help_gem_port(self): |
| 1568 | self.poutput( |
| 1569 | ''' |
| 1570 | gem_port [get | create | update | delete] |
| 1571 | [-n <name>] [-r <interface reference>] [-c <traffic class>] |
| 1572 | [-a <aes indicator>] [-t <tcont reference>] |
| 1573 | |
| 1574 | get: displays existing gemports |
| 1575 | Required flags: None |
| 1576 | create: creates gemport with the parameters specified with |
| 1577 | -n, -r, -c, -a, and -t. |
| 1578 | Required flags: <name>, <interface reference>, <traffic class> |
| 1579 | update: updates existing gemport specified with parameter -n |
| 1580 | by changing its parameter values specified with -r, -c, -a, and -t. |
| 1581 | Required flags: <name> |
| 1582 | delete: deletes gemport specified with parameter -n. |
| 1583 | Required flags: <name> |
| 1584 | |
| 1585 | -n: <string> name of gemport. |
| 1586 | -r: <string> reference to v_enet interface. |
| 1587 | -c: <int> traffic class value for gemport. |
| 1588 | -a: <bool> aes indicator that is used to designate whether AES should be |
| 1589 | enabled/disabled for all bi-directional GEM ports associated with |
| 1590 | this ONT. |
| 1591 | -t: <string> tcont reference that is for the purpose of upstream scheduling in |
| 1592 | the ONU, a gemport needs to refer to the tcont into which it feeds |
| 1593 | upstream traffic. |
Chip Boling | 97bef1e | 2017-08-29 11:44:28 -0500 | [diff] [blame] | 1594 | -g: <int> gemport ID. If not provided, xPON Manager will provide the gemport ID. |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1595 | |
| 1596 | Example: |
| 1597 | |
Chip Boling | 97bef1e | 2017-08-29 11:44:28 -0500 | [diff] [blame] | 1598 | gem_port create -n "GEMPORT 1" -r "Enet UNI 1" -c 0 -a true -t "TCont 1" -g 2044 |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1599 | ''' |
| 1600 | ) |
| 1601 | |
| 1602 | @options([ |
| 1603 | make_option('-n', '--name', action="store", dest='name', type='string', |
| 1604 | help='name of gemport', default=None), |
| 1605 | make_option('-r', '--itf_ref', action="store", dest='itf_ref', |
| 1606 | type='string', help='reference to v_enet interface', |
| 1607 | default=None), |
| 1608 | make_option('-c', '--traffic_class', action="store", |
| 1609 | dest='traffic_class', type='int', |
| 1610 | help='traffic class value for gemport', default=None), |
| 1611 | make_option('-a', '--aes_indicator', action="store", |
| 1612 | dest='aes_indicator', type='string', |
| 1613 | help='aes indicator to designate if AES enabled/disabled', |
| 1614 | default=None), |
| 1615 | make_option('-t', '--tcont_ref', action='store', dest='tcont_ref', |
| 1616 | type='string', |
| 1617 | help='tcont reference for purpose of us scheduling in ONU', |
| 1618 | default=None), |
Chip Boling | 97bef1e | 2017-08-29 11:44:28 -0500 | [diff] [blame] | 1619 | make_option('-g', '--gemport_id', action='store', dest='gemport_id', |
| 1620 | type='int', help='GEMPORT ID', default=None), |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1621 | ]) |
| 1622 | |
| 1623 | def do_gem_port(self, line, opts): |
| 1624 | """gem_port get, create -flags <attributes>, |
| 1625 | update -flags <attributes>, delete -n <name>""" |
| 1626 | # Ensure that a valid sub-command was provided |
| 1627 | if line.strip() not in {"get", "create", "update", "delete"}: |
| 1628 | self.poutput(self.colorize('Error: ', 'red') + |
| 1629 | self.colorize(self.colorize(line.strip(), 'blue'), |
| 1630 | 'bold') + ' is not recognized') |
| 1631 | return |
| 1632 | |
| 1633 | stub = voltha_pb2.VolthaGlobalServiceStub(self.get_channel()) |
| 1634 | |
| 1635 | if line.strip() == "get": |
| 1636 | if self.device_id: |
| 1637 | cg, cpart, cp, ct, vont, ont, venet, tdp, tcont, gemport = \ |
| 1638 | self.get_interface_based_on_device() |
| 1639 | print_pb_list_as_table( |
| 1640 | "Gem Ports for device ID = {}:" |
| 1641 | .format(self.device_id), gemport, {}, self.poutput) |
| 1642 | else: |
| 1643 | gemport = stub.GetAllGemportsConfigData(Empty()) |
| 1644 | print_pb_list_as_table("Gem Ports:", |
| 1645 | gemport.gemports_config, |
| 1646 | {}, self.poutput) |
| 1647 | return |
| 1648 | try: |
| 1649 | gemport = GemportsConfigData(name = opts.name) |
| 1650 | if opts.itf_ref: |
| 1651 | gemport.itf_ref = opts.itf_ref |
| 1652 | if opts.traffic_class: |
| 1653 | gemport.traffic_class = opts.traffic_class |
| 1654 | if opts.aes_indicator: |
| 1655 | if opts.aes_indicator == 'true': |
| 1656 | gemport.aes_indicator = True |
| 1657 | elif opts.aes_indicator == 'false': |
| 1658 | gemport.aes_indicator = False |
| 1659 | else: |
| 1660 | m = 'Invalid boolean value for Gem Port \ |
| 1661 | aes_indicator \'{}\''.format(opts.aes_indicator) |
| 1662 | self.poutput( |
| 1663 | self.colorize('Error: ', 'red') + self.colorize( |
| 1664 | self.colorize(m, 'blue'), 'bold')) |
| 1665 | return |
| 1666 | if opts.tcont_ref: |
| 1667 | gemport.tcont_ref = opts.tcont_ref |
Chip Boling | 97bef1e | 2017-08-29 11:44:28 -0500 | [diff] [blame] | 1668 | if opts.gemport_id: |
| 1669 | gemport.gemport_id = opts.gemport_id |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 1670 | if line.strip() == "create": |
| 1671 | stub.CreateGemportsConfigData(gemport) |
| 1672 | elif line.strip() == "update": |
| 1673 | stub.UpdateGemportsConfigData(gemport) |
| 1674 | elif line.strip() == "delete": |
| 1675 | stub.DeleteGemportsConfigData(gemport) |
| 1676 | return |
| 1677 | except Exception, e: |
| 1678 | self.poutput( |
| 1679 | self.colorize('Error: ', 'red') + |
| 1680 | self.colorize(self.colorize(e.message, 'blue'), 'bold')) |
| 1681 | return |