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