blob: 2f591d370213d5c17ddaee8682a53ada8e5e79e1 [file] [log] [blame]
Marc De Leenheerb9311372015-07-09 11:36:49 -07001/*
2 * Copyright 2015 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.handshaker;
17
18import com.google.common.collect.ImmutableList;
19import com.google.common.collect.ImmutableSet;
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -080020import org.onlab.util.Spectrum;
21import org.onosproject.net.ChannelSpacing;
22import org.onosproject.net.DefaultOchSignalComparator;
Marc De Leenheerb9311372015-07-09 11:36:49 -070023import org.onosproject.net.Device;
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -080024import org.onosproject.net.GridType;
25import org.onosproject.net.OchSignal;
26import org.onosproject.net.PortNumber;
27import org.onosproject.net.behaviour.LambdaQuery;
Marc De Leenheerb9311372015-07-09 11:36:49 -070028import org.onosproject.openflow.controller.OpenFlowOpticalSwitch;
29import org.onosproject.openflow.controller.PortDescPropertyType;
30import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
31import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted;
32import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted;
33import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted;
34import org.projectfloodlight.openflow.protocol.OFCalientFlowStatsRequest;
35import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsEntry;
36import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsReply;
37import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsRequest;
38import org.projectfloodlight.openflow.protocol.OFFlowStatsRequest;
39import org.projectfloodlight.openflow.protocol.OFMessage;
40import org.projectfloodlight.openflow.protocol.OFObject;
41import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags;
42import org.projectfloodlight.openflow.protocol.OFStatsRequest;
43import org.projectfloodlight.openflow.protocol.OFType;
44import org.projectfloodlight.openflow.types.OFPort;
45import org.projectfloodlight.openflow.types.TableId;
46
47import java.io.IOException;
48import java.util.ArrayList;
49import java.util.List;
50import java.util.Set;
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -080051import java.util.SortedSet;
52import java.util.TreeSet;
Marc De Leenheerb9311372015-07-09 11:36:49 -070053import java.util.concurrent.atomic.AtomicBoolean;
Marc De Leenheer2c305302015-12-07 21:37:44 -080054import java.util.function.Supplier;
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -080055import java.util.stream.Collectors;
56import java.util.stream.IntStream;
Marc De Leenheerb9311372015-07-09 11:36:49 -070057
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -080058/**
59 * Driver for Calient S160 Optical Circuit Switch. Untested on Calient S320 but probably works ok.
60 *
61 * Driver implements custom handshaker, and rewrites flow stats as expected by the device. Port stats are currently
62 * not supported.
63 *
64 * The device consists of OMS ports only, and each port exposes lambda resources covering the whole
65 * usable optical spectrum (U to O band, see {@link Spectrum} for spectrum definitions).
66 */
67public class CalientFiberSwitchHandshaker
68 extends AbstractOpenFlowSwitch
69 implements OpenFlowOpticalSwitch, LambdaQuery {
Marc De Leenheerb9311372015-07-09 11:36:49 -070070
71 private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false);
72 private List<OFCalientPortDescStatsEntry> fiberPorts = new ArrayList<>();
73
74
75 @Override
76 public Boolean supportNxRole() {
77 return false;
78 }
79
80 @Override
81 public void startDriverHandshake() {
82 log.warn("Starting driver handshake for sw {}", getStringId());
83 if (startDriverHandshakeCalled) {
84 throw new SwitchDriverSubHandshakeAlreadyStarted();
85 }
86 startDriverHandshakeCalled = true;
87 try {
88 sendHandshakeOFExperimenterPortDescRequest();
89 } catch (IOException e) {
90 log.error("Exception while sending experimenter port desc:", e.getMessage());
91 e.printStackTrace();
92 }
93
94 }
95
96 private void sendHandshakeOFExperimenterPortDescRequest() throws IOException {
97 // send multi part message for port description for optical switches
98 OFCalientPortDescStatsRequest portsRequest = factory()
99 .buildCalientPortDescStatsRequest()
100 .build();
101 log.warn("Sending experimenter port description message {}",
102 portsRequest.toString());
103 this.sendHandshakeMessage(portsRequest);
104 }
105
106 @Override
107 public boolean isDriverHandshakeComplete() {
108 return driverHandshakeComplete.get();
109 }
110
111 @Override
112 public void processDriverHandshakeMessage(OFMessage m) {
113 if (!startDriverHandshakeCalled) {
114 throw new SwitchDriverSubHandshakeNotStarted();
115 }
116 if (driverHandshakeComplete.get()) {
117 throw new SwitchDriverSubHandshakeCompleted(m);
118 }
119
120 switch (m.getType()) {
121 case BARRIER_REPLY:
122 break;
123 case ERROR:
124 log.error("Switch Error {} {}", getStringId(), m);
125 break;
126 case FEATURES_REPLY:
127 break;
128 case FLOW_REMOVED:
129 break;
130 case GET_ASYNC_REPLY:
131 break;
132 case PACKET_IN:
133 break;
134 case PORT_STATUS:
135 break;
136 case QUEUE_GET_CONFIG_REPLY:
137 break;
138 case ROLE_REPLY:
139 break;
140 case STATS_REPLY:
141 log.warn("Received port desc reply");
142 OFCalientPortDescStatsReply descStatsReply = (OFCalientPortDescStatsReply) m;
143 fiberPorts.addAll(descStatsReply.getPortDesc());
144 // Multi-part message
145 if (!descStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
146 driverHandshakeComplete.set(true);
147 }
148 break;
149 default:
150 log.warn("Received message {} during switch-driver " +
151 "subhandshake " + "from switch {} ... " +
152 "Ignoring message", m,
153 getStringId());
154
155 }
156 }
157
158 @Override
159 public Device.Type deviceType() {
160 return Device.Type.FIBER_SWITCH;
161 }
162
163 @Override
164 public List<? extends OFObject> getPortsOf(PortDescPropertyType type) {
165 return ImmutableList.copyOf(fiberPorts);
166 }
167
168 @Override
169 public Set<PortDescPropertyType> getPortTypes() {
170 return ImmutableSet.of(PortDescPropertyType.OPTICAL_TRANSPORT);
171 }
172
173 @Override
174 public final void sendMsg(OFMessage m) {
175 OFMessage newMsg = m;
176
177 if (m.getType() == OFType.STATS_REQUEST) {
178 OFStatsRequest sr = (OFStatsRequest) m;
179 log.debug("Rebuilding stats request type {}", sr.getStatsType());
180 switch (sr.getStatsType()) {
181 case FLOW:
182 OFCalientFlowStatsRequest request = this.factory().buildCalientFlowStatsRequest()
183 .setCookie(((OFFlowStatsRequest) sr).getCookie())
184 .setCookieMask(((OFFlowStatsRequest) sr).getCookieMask())
185 .setMatch(this.factory().matchWildcardAll())
186 .setOutGroup(((OFFlowStatsRequest) sr).getOutGroup().getGroupNumber())
187 .setOutPort(OFPort.ANY)
188 .setTableId(TableId.ALL)
189 .setXid(sr.getXid())
190 .setFlags(sr.getFlags())
191 .build();
192 newMsg = request;
193 break;
194 case PORT:
195 // TODO
196 break;
197 default:
198 break;
199 }
200 }
201
202 super.sendMsg(newMsg);
203 }
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -0800204
205 @Override
206 public SortedSet<OchSignal> queryLambdas(PortNumber port) {
207 // S160 data sheet
208 // Wavelength range: 1260 - 1630 nm
209 long startSpacingMultiplier = Spectrum.U_BAND_MIN.subtract(Spectrum.CENTER_FREQUENCY).asHz() /
210 ChannelSpacing.CHL_12P5GHZ.frequency().asHz();
211 long stopSpacingMultiplier = Spectrum.O_BAND_MAX.subtract(Spectrum.CENTER_FREQUENCY).asHz() /
212 ChannelSpacing.CHL_12P5GHZ.frequency().asHz();
Marc De Leenheer2c305302015-12-07 21:37:44 -0800213 Supplier<SortedSet<OchSignal>> supplier = () -> new TreeSet<>(new DefaultOchSignalComparator());
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -0800214
Marc De Leenheer2c305302015-12-07 21:37:44 -0800215 // Only consider odd values for the multiplier (for easy mapping to fixed grid)
216 return IntStream.rangeClosed((int) startSpacingMultiplier, (int) stopSpacingMultiplier)
217 .filter(i -> i % 2 == 1)
218 .mapToObj(i -> new OchSignal(GridType.FLEX, ChannelSpacing.CHL_6P25GHZ, i, 1))
219 .collect(Collectors.toCollection(supplier));
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -0800220 }
Marc De Leenheerb9311372015-07-09 11:36:49 -0700221}