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; |
| 52 | import java.util.TreeSet; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 53 | import java.util.concurrent.atomic.AtomicBoolean; |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 54 | import java.util.function.Supplier; |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 55 | import java.util.stream.Collectors; |
| 56 | import java.util.stream.IntStream; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 57 | |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 58 | /** |
| 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 | */ |
| 67 | public class CalientFiberSwitchHandshaker |
| 68 | extends AbstractOpenFlowSwitch |
| 69 | implements OpenFlowOpticalSwitch, LambdaQuery { |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 70 | |
| 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 Milkey | 4fd3ceb | 2015-12-10 14:43:08 -0800 | [diff] [blame^] | 90 | log.error("Exception while sending experimenter port desc:", e); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 91 | } |
| 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 Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 203 | |
| 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 Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 212 | Supplier<SortedSet<OchSignal>> supplier = () -> new TreeSet<>(new DefaultOchSignalComparator()); |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 213 | |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 214 | // 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 Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 219 | } |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 220 | } |