blob: 493ac2f1255e1e4a9b00f6d1b38bf4ec393af81d [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) {
Ray Milkey4fd3ceb2015-12-10 14:43:08 -080090 log.error("Exception while sending experimenter port desc:", e);
Marc De Leenheerb9311372015-07-09 11:36:49 -070091 }
92
93 }
94
95 private void sendHandshakeOFExperimenterPortDescRequest() throws IOException {
96 // send multi part message for port description for optical switches
97 OFCalientPortDescStatsRequest portsRequest = factory()
98 .buildCalientPortDescStatsRequest()
99 .build();
100 log.warn("Sending experimenter port description message {}",
101 portsRequest.toString());
102 this.sendHandshakeMessage(portsRequest);
103 }
104
105 @Override
106 public boolean isDriverHandshakeComplete() {
107 return driverHandshakeComplete.get();
108 }
109
110 @Override
111 public void processDriverHandshakeMessage(OFMessage m) {
112 if (!startDriverHandshakeCalled) {
113 throw new SwitchDriverSubHandshakeNotStarted();
114 }
115 if (driverHandshakeComplete.get()) {
116 throw new SwitchDriverSubHandshakeCompleted(m);
117 }
118
119 switch (m.getType()) {
120 case BARRIER_REPLY:
121 break;
122 case ERROR:
123 log.error("Switch Error {} {}", getStringId(), m);
124 break;
125 case FEATURES_REPLY:
126 break;
127 case FLOW_REMOVED:
128 break;
129 case GET_ASYNC_REPLY:
130 break;
131 case PACKET_IN:
132 break;
133 case PORT_STATUS:
134 break;
135 case QUEUE_GET_CONFIG_REPLY:
136 break;
137 case ROLE_REPLY:
138 break;
139 case STATS_REPLY:
140 log.warn("Received port desc reply");
141 OFCalientPortDescStatsReply descStatsReply = (OFCalientPortDescStatsReply) m;
142 fiberPorts.addAll(descStatsReply.getPortDesc());
143 // Multi-part message
144 if (!descStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
145 driverHandshakeComplete.set(true);
146 }
147 break;
148 default:
149 log.warn("Received message {} during switch-driver " +
150 "subhandshake " + "from switch {} ... " +
151 "Ignoring message", m,
152 getStringId());
153
154 }
155 }
156
157 @Override
158 public Device.Type deviceType() {
159 return Device.Type.FIBER_SWITCH;
160 }
161
162 @Override
163 public List<? extends OFObject> getPortsOf(PortDescPropertyType type) {
164 return ImmutableList.copyOf(fiberPorts);
165 }
166
167 @Override
168 public Set<PortDescPropertyType> getPortTypes() {
169 return ImmutableSet.of(PortDescPropertyType.OPTICAL_TRANSPORT);
170 }
171
172 @Override
173 public final void sendMsg(OFMessage m) {
174 OFMessage newMsg = m;
175
176 if (m.getType() == OFType.STATS_REQUEST) {
177 OFStatsRequest sr = (OFStatsRequest) m;
178 log.debug("Rebuilding stats request type {}", sr.getStatsType());
179 switch (sr.getStatsType()) {
180 case FLOW:
181 OFCalientFlowStatsRequest request = this.factory().buildCalientFlowStatsRequest()
182 .setCookie(((OFFlowStatsRequest) sr).getCookie())
183 .setCookieMask(((OFFlowStatsRequest) sr).getCookieMask())
184 .setMatch(this.factory().matchWildcardAll())
185 .setOutGroup(((OFFlowStatsRequest) sr).getOutGroup().getGroupNumber())
186 .setOutPort(OFPort.ANY)
187 .setTableId(TableId.ALL)
188 .setXid(sr.getXid())
189 .setFlags(sr.getFlags())
190 .build();
191 newMsg = request;
192 break;
193 case PORT:
194 // TODO
195 break;
196 default:
197 break;
198 }
199 }
200
201 super.sendMsg(newMsg);
202 }
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -0800203
204 @Override
205 public SortedSet<OchSignal> queryLambdas(PortNumber port) {
206 // S160 data sheet
207 // Wavelength range: 1260 - 1630 nm
208 long startSpacingMultiplier = Spectrum.U_BAND_MIN.subtract(Spectrum.CENTER_FREQUENCY).asHz() /
209 ChannelSpacing.CHL_12P5GHZ.frequency().asHz();
210 long stopSpacingMultiplier = Spectrum.O_BAND_MAX.subtract(Spectrum.CENTER_FREQUENCY).asHz() /
211 ChannelSpacing.CHL_12P5GHZ.frequency().asHz();
Marc De Leenheer2c305302015-12-07 21:37:44 -0800212 Supplier<SortedSet<OchSignal>> supplier = () -> new TreeSet<>(new DefaultOchSignalComparator());
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -0800213
Marc De Leenheer2c305302015-12-07 21:37:44 -0800214 // Only consider odd values for the multiplier (for easy mapping to fixed grid)
215 return IntStream.rangeClosed((int) startSpacingMultiplier, (int) stopSpacingMultiplier)
216 .filter(i -> i % 2 == 1)
217 .mapToObj(i -> new OchSignal(GridType.FLEX, ChannelSpacing.CHL_6P25GHZ, i, 1))
218 .collect(Collectors.toCollection(supplier));
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -0800219 }
Marc De Leenheerb9311372015-07-09 11:36:49 -0700220}