blob: f4dc266fa60c59bbcfbfe4abc12a20f369935521 [file] [log] [blame]
Yuta HIGUCHIa4bb84e2017-03-11 17:47:12 -08001/*
2 * Copyright 2017-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.driver.optical.config;
17
18import java.util.ArrayList;
19import java.util.List;
20import java.util.Optional;
21
22import org.onlab.packet.ChassisId;
23import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.Device;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.Port;
27import org.onosproject.net.PortNumber;
28import org.onosproject.net.config.NetworkConfigService;
29import org.onosproject.net.config.basics.BasicDeviceConfig;
30import org.onosproject.net.config.inject.DeviceInjectionConfig;
31import org.onosproject.net.device.DefaultDeviceDescription;
32import org.onosproject.net.device.DefaultPortDescription;
33import org.onosproject.net.device.DeviceDescription;
34import org.onosproject.net.device.DeviceDescriptionDiscovery;
35import org.onosproject.net.device.PortDescription;
36import org.onosproject.net.driver.AbstractHandlerBehaviour;
37import org.onosproject.net.optical.config.OpticalPortConfig;
38
39import com.google.common.annotations.Beta;
40import com.google.common.collect.ImmutableList;
41/*
42 * Example:
43 * CHECKSTYLE:OFF
44{
45 "ports" : {
46 "inject:10.49.54.31/1" : {
47
48# see OpticalPortConfig
49 "optical" : {
50 "type" : "OCH"
51 },
52# Annotations required by projection mechanism. see OchPortHelper, etc.
53 "annotations" : {
54 "entries" : {
55 "comment" : "following is required annotations for OCH port",
56 "tunable" : "true",
57 "lambda" : "{ \"gridType\": \"FLEX\", \"channelSpacing\": \"CHL_6P25GHZ\", \"spacingMultiplier\": 42, \"slotGranularity\": 1 }",
58 "signalType" : "ODUC4"
59 }
60 },
61# see ConfigLambdaQuery
62 "lambdas" : {
63 "gridType" : "DWDM",
64 "dwdmSpacing" : "CHL_50GHZ",
65 "slotStart" : 1,
66 "slotSttep" : 1,
67 "slotEnd" : 5
68 }
69 },
70
71 "inject:10.49.54.31/2" : {
72 "optical" : {
73 "type" : "OMS"
74 },
75 "annotations" : {
76 "entries" : {
77 "comment" : "following is required annotations for OMS port",
78 "minFrequency" : "178981000000000",
79 "maxFrequency" : "237931000000000",
80 "grid" : "100000000000"
81 }
82 },
83 "lambdas" : {
84 "gridType" : "FLEX",
85 "slotStart" : 1,
86 "slotStep" : 2,
87 "slotEnd" : 3585
88 }
89 },
90
91 "inject:10.49.54.31/3" : {
92 "optical" : {
93 "type" : "ODUCLT",
94 "speed" : 100000
95 },
96 "annotations" : {
97 "entries" : {
98 "comment" : "following is required annotations for ODUCLT port",
99 "signalType" : "CLT_100GBE"
100 }
101 }
102 },
103
104 "inject:10.49.54.31/4" : {
105 "optical" : {
106 "speed" : 100000
107 }
108 }
109 },
110#
111# Note: "ports" must be defined before "devices" when submitting in single tx.
112#
113 "devices" : {
114 "inject:10.49.54.31" : {
115 "basic" : {
116# specify driver to use ConfigOpticalDeviceDiscovery, etc.
117 "driver" : "optical-config",
118 "type" : "ROADM_OTN",
119 "hwVersion" : "1.0",
120 "swVersion" : "2.0",
121 "serial" : "R-3000"
122 },
123 "inject" : {
124# This device has 5 ports [1-5]
125# details defined in /ports tree above.
126 "ports" : "5"
127 }
128 }
129 }
130}
131 * CHECKSTYLE:ON
132 */
133
134/**
135 * DeviceDescriptionDiscovery implementation, which
136 * utilizes {@link DeviceInjectionConfig}, {@link BasicDeviceConfig},
137 * {@link OpticalPortConfig} to populate Device and Ports based on configuration.
138 */
139@Beta
140public class ConfigOpticalDeviceDiscovery extends AbstractHandlerBehaviour
141 implements DeviceDescriptionDiscovery {
142
143 @Override
144 public DeviceDescription discoverDeviceDetails() {
145 NetworkConfigService netcfg = handler().get(NetworkConfigService.class);
146 DeviceId did = data().deviceId();
147
148 String unk = "UNKNOWN";
149
150 Optional<DeviceInjectionConfig> inject =
151 Optional.ofNullable(netcfg.getConfig(did, DeviceInjectionConfig.class));
152
153 Optional<BasicDeviceConfig> basic =
154 Optional.ofNullable(netcfg.getConfig(did, BasicDeviceConfig.class));
155
156 Device.Type type = basic.map(BasicDeviceConfig::type).orElse(Device.Type.SWITCH);
157 String manufacturer = basic.map(BasicDeviceConfig::manufacturer).orElse(unk);
158 String hwVersion = basic.map(BasicDeviceConfig::hwVersion).orElse(unk);
159 String swVersion = basic.map(BasicDeviceConfig::swVersion).orElse(unk);
160 String serialNumber = basic.map(BasicDeviceConfig::serial).orElse(unk);
161 ChassisId chassis = new ChassisId();
162 // if inject is not specified, return default unavailable device
163 boolean defaultAvailable = inject.isPresent();
164 return new DefaultDeviceDescription(did.uri(),
165 type,
166 manufacturer,
167 hwVersion,
168 swVersion,
169 serialNumber,
170 chassis,
171 defaultAvailable);
172 }
173
174 @Override
175 public List<PortDescription> discoverPortDetails() {
176 NetworkConfigService netcfg = handler().get(NetworkConfigService.class);
177 DeviceId did = data().deviceId();
178
179 DeviceInjectionConfig cfg = netcfg.getConfig(did, DeviceInjectionConfig.class);
180 if (cfg == null) {
181 return ImmutableList.of();
182 }
183 String ports = cfg.ports();
184 // TODO: parse port format like [1-3,6] in the future
185 int numPorts = Integer.parseInt(ports);
186
187 List<PortDescription> portDescs = new ArrayList<>(numPorts);
188 for (int i = 1; i <= numPorts; ++i) {
189 PortNumber number = PortNumber.portNumber(i);
190 ConnectPoint cp = new ConnectPoint(did, number);
191
192 Optional<OpticalPortConfig> port =
193 Optional.ofNullable(netcfg.getConfig(cp, OpticalPortConfig.class));
194
195 boolean isEnabled = true;
196 // default packet port speed on configured-optical device (in Mbps)
197 int speedFallback = 10_000;
198 long portSpeed = port.flatMap(OpticalPortConfig::speed).orElse(speedFallback);
199 Port.Type type = port.map(OpticalPortConfig::type).orElse(Port.Type.COPPER);
200
201 portDescs.add(new DefaultPortDescription(number, isEnabled, type, portSpeed));
202 }
203
204 return portDescs;
205 }
206
207}