Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.driver.handshaker; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
| 19 | import com.google.common.collect.ImmutableSet; |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 20 | import org.onlab.util.Spectrum; |
| 21 | import org.onosproject.net.ChannelSpacing; |
| 22 | import org.onosproject.net.DefaultOchSignalComparator; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 23 | import org.onosproject.net.Device; |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 24 | import org.onosproject.net.GridType; |
| 25 | import org.onosproject.net.OchSignal; |
| 26 | import org.onosproject.net.PortNumber; |
| 27 | import org.onosproject.net.behaviour.LambdaQuery; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 28 | import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; |
| 29 | import org.onosproject.openflow.controller.PortDescPropertyType; |
| 30 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; |
| 31 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted; |
| 32 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted; |
| 33 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted; |
| 34 | import org.projectfloodlight.openflow.protocol.OFCalientFlowStatsRequest; |
| 35 | import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsEntry; |
| 36 | import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsReply; |
| 37 | import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsRequest; |
| 38 | import org.projectfloodlight.openflow.protocol.OFFlowStatsRequest; |
| 39 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 40 | import org.projectfloodlight.openflow.protocol.OFObject; |
| 41 | import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; |
| 42 | import org.projectfloodlight.openflow.protocol.OFStatsRequest; |
| 43 | import org.projectfloodlight.openflow.protocol.OFType; |
| 44 | import org.projectfloodlight.openflow.types.OFPort; |
| 45 | import org.projectfloodlight.openflow.types.TableId; |
| 46 | |
| 47 | import java.io.IOException; |
| 48 | import java.util.ArrayList; |
| 49 | import java.util.List; |
| 50 | import java.util.Set; |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 51 | import java.util.SortedSet; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 52 | import java.util.concurrent.atomic.AtomicBoolean; |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 53 | import java.util.stream.Collectors; |
| 54 | import java.util.stream.IntStream; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 55 | |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 56 | /** |
| 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 | */ |
| 65 | public class CalientFiberSwitchHandshaker |
| 66 | extends AbstractOpenFlowSwitch |
| 67 | implements OpenFlowOpticalSwitch, LambdaQuery { |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 68 | |
| 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 Milkey | 4fd3ceb | 2015-12-10 14:43:08 -0800 | [diff] [blame] | 88 | log.error("Exception while sending experimenter port desc:", e); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 89 | } |
| 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 Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 201 | |
| 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 Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 210 | |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 211 | // 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 Leenheer | cef4555 | 2015-12-14 19:59:59 -0800 | [diff] [blame] | 215 | .collect(Collectors.toCollection(DefaultOchSignalComparator::newOchSignalTreeSet)); |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 216 | } |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 217 | } |