Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 2 | * Copyright 2015 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 16 | package org.onosproject.driver.handshaker; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 17 | |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 19 | import org.onosproject.net.ChannelSpacing; |
| 20 | import org.onosproject.net.DefaultOchSignalComparator; |
Marc De Leenheer | c2999f3 | 2015-11-20 15:52:16 -0800 | [diff] [blame] | 21 | import org.onosproject.net.Device; |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 22 | import org.onosproject.net.GridType; |
| 23 | import org.onosproject.net.OchSignal; |
| 24 | import org.onosproject.net.PortNumber; |
| 25 | import org.onosproject.net.behaviour.LambdaQuery; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 26 | import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; |
| 27 | import org.onosproject.openflow.controller.PortDescPropertyType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 28 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; |
| 29 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted; |
| 30 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted; |
| 31 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 32 | import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 33 | import org.projectfloodlight.openflow.protocol.OFCircuitPortsReply; |
| 34 | import org.projectfloodlight.openflow.protocol.OFCircuitPortsRequest; |
Marc De Leenheer | c2999f3 | 2015-11-20 15:52:16 -0800 | [diff] [blame] | 35 | import org.projectfloodlight.openflow.protocol.OFFlowMod; |
| 36 | import org.projectfloodlight.openflow.protocol.OFFlowStatsRequest; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 37 | import org.projectfloodlight.openflow.protocol.OFMessage; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 38 | import org.projectfloodlight.openflow.protocol.OFObject; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 39 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 40 | import org.projectfloodlight.openflow.protocol.OFPortDescPropOpticalTransport; |
| 41 | import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; |
| 42 | import org.projectfloodlight.openflow.protocol.OFPortOptical; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 43 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
| 44 | import org.projectfloodlight.openflow.protocol.OFStatsType; |
Marc De Leenheer | c2999f3 | 2015-11-20 15:52:16 -0800 | [diff] [blame] | 45 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
| 46 | import org.projectfloodlight.openflow.protocol.action.OFActionSetField; |
| 47 | import org.projectfloodlight.openflow.protocol.match.Match; |
| 48 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
| 49 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmExpOchSigId; |
| 50 | import org.projectfloodlight.openflow.types.CircuitSignalID; |
Marc De Leenheer | c2999f3 | 2015-11-20 15:52:16 -0800 | [diff] [blame] | 51 | import org.projectfloodlight.openflow.types.U8; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 52 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 53 | import java.io.IOException; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 54 | import java.util.ArrayList; |
| 55 | import java.util.Collections; |
Marc De Leenheer | c2999f3 | 2015-11-20 15:52:16 -0800 | [diff] [blame] | 56 | import java.util.LinkedList; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 57 | import java.util.List; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 58 | import java.util.Set; |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 59 | import java.util.SortedSet; |
| 60 | import java.util.TreeSet; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 61 | import java.util.concurrent.atomic.AtomicBoolean; |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 62 | import java.util.function.Supplier; |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 63 | import java.util.stream.Collectors; |
| 64 | import java.util.stream.IntStream; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * LINC-OE Optical Emulator switch class. |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 68 | * |
| 69 | * The LINC ROADM emulator exposes two types of ports: OCh ports connect to ports in the packet layer, |
| 70 | * while OMS ports connect to an OMS port on a neighbouring ROADM. |
| 71 | * |
| 72 | * LINC sends the tap ports (OCh for our purposes) in the regular port desc stats reply, |
| 73 | * while it sends *all* ports (both tap and WDM ports, i.e., OCh and OMS) in the experimenter port desc stats reply. |
| 74 | * |
Marc De Leenheer | c2999f3 | 2015-11-20 15:52:16 -0800 | [diff] [blame] | 75 | * As LINC implements custom OF optical extensions (in contrast to the final standard as specified in |
| 76 | * ONF TS-022 (March 15, 2015), we need to rewrite flow stat requests and flow mods in {@link #sendMsg(OFMessage)}. |
| 77 | * |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 78 | * LINC exposes OchSignal resources: 80 lambdas of 50 GHz (fixed grid) around ITU-T G.694.1 center frequency 193.1 GHz. |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 79 | * |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 80 | */ |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 81 | public class OfOpticalSwitchImplLinc13 |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 82 | extends AbstractOpenFlowSwitch implements OpenFlowOpticalSwitch, LambdaQuery { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 83 | |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 84 | private static final int LAMBDA_COUNT = 80; |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 85 | private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 86 | private long barrierXidToWaitFor = -1; |
| 87 | |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 88 | private List<OFPortOptical> opticalPorts; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 89 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 90 | @Override |
| 91 | public void startDriverHandshake() { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 92 | log.warn("Starting driver handshake for sw {}", getStringId()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 93 | if (startDriverHandshakeCalled) { |
| 94 | throw new SwitchDriverSubHandshakeAlreadyStarted(); |
| 95 | } |
| 96 | startDriverHandshakeCalled = true; |
| 97 | try { |
| 98 | sendHandshakeOFExperimenterPortDescRequest(); |
| 99 | } catch (IOException e) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 100 | log.error("LINC-OE exception while sending experimenter port desc:", |
| 101 | e.getMessage()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 102 | e.printStackTrace(); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public boolean isDriverHandshakeComplete() { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 108 | return driverHandshakeComplete.get(); |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public void processDriverHandshakeMessage(OFMessage m) { |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 113 | if (!startDriverHandshakeCalled) { |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 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 | if (m.getXid() == barrierXidToWaitFor) { |
| 123 | log.debug("LINC-OE Received barrier response"); |
| 124 | } |
| 125 | break; |
| 126 | case ERROR: |
Yuta HIGUCHI | f5416d8 | 2014-10-24 21:17:40 -0700 | [diff] [blame] | 127 | log.error("Switch {} Error {}", getStringId(), m); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 128 | break; |
| 129 | case FEATURES_REPLY: |
| 130 | break; |
| 131 | case FLOW_REMOVED: |
| 132 | break; |
| 133 | case GET_ASYNC_REPLY: |
| 134 | break; |
| 135 | case PACKET_IN: |
| 136 | break; |
| 137 | case PORT_STATUS: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 138 | log.warn("****LINC-OE Port Status {} {}", getStringId(), m); |
| 139 | processOFPortStatus((OFCircuitPortStatus) m); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 140 | break; |
| 141 | case QUEUE_GET_CONFIG_REPLY: |
| 142 | break; |
| 143 | case ROLE_REPLY: |
| 144 | break; |
| 145 | case STATS_REPLY: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 146 | OFStatsReply stats = (OFStatsReply) m; |
| 147 | if (stats.getStatsType() == OFStatsType.EXPERIMENTER) { |
| 148 | log.warn("LINC-OE : Received stats reply message {}", m); |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 149 | createOpticalPortList((OFCircuitPortsReply) m); |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 150 | driverHandshakeComplete.set(true); |
| 151 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 152 | break; |
| 153 | default: |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 154 | log.warn("Received message {} during switch-driver " + |
| 155 | "subhandshake " + "from switch {} ... " + |
| 156 | "Ignoring message", m, |
| 157 | getStringId()); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 158 | |
| 159 | } |
| 160 | } |
| 161 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 162 | public void processOFPortStatus(OFCircuitPortStatus ps) { |
| 163 | log.debug("LINC-OE ..OF Port Status :", ps); |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 164 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 165 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 166 | private void sendHandshakeOFExperimenterPortDescRequest() throws |
| 167 | IOException { |
| 168 | // send multi part message for port description for optical switches |
| 169 | OFCircuitPortsRequest circuitPortsRequest = factory() |
| 170 | .buildCircuitPortsRequest().setXid(getNextTransactionId()) |
| 171 | .build(); |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 172 | log.warn("LINC-OE : Sending experimented circuit port stats " + |
| 173 | "message " + |
| 174 | "{}", |
| 175 | circuitPortsRequest.toString()); |
alshabib | a2df7b2a | 2015-05-06 13:57:10 -0700 | [diff] [blame] | 176 | this.sendHandshakeMessage(circuitPortsRequest); |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 179 | @Override |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 180 | /** |
| 181 | * Returns a list of standard (Ethernet) ports. |
| 182 | * |
| 183 | * @return List of ports |
| 184 | */ |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 185 | public List<OFPortDesc> getPorts() { |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 186 | return Collections.EMPTY_LIST; |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Marc De Leenheer | c2999f3 | 2015-11-20 15:52:16 -0800 | [diff] [blame] | 189 | /** |
| 190 | * Rewrite match object to use LINC OF optical extensions. |
| 191 | * |
| 192 | * @param match original match |
| 193 | * @return rewritten match |
| 194 | */ |
| 195 | private Match rewriteMatch(Match match) { |
| 196 | Match.Builder mBuilder = factory().buildMatch(); |
| 197 | for (MatchField mf : match.getMatchFields()) { |
| 198 | if (mf == MatchField.EXP_OCH_SIG_ID) { |
| 199 | mBuilder.setExact(MatchField.OCH_SIGID, (CircuitSignalID) match.get(mf)); |
| 200 | continue; |
| 201 | } |
| 202 | if (mf == MatchField.EXP_OCH_SIGTYPE) { |
| 203 | mBuilder.setExact(MatchField.OCH_SIGTYPE, (U8) match.get(mf)); |
| 204 | continue; |
| 205 | } |
| 206 | mBuilder.setExact(mf, match.get(mf)); |
| 207 | } |
| 208 | |
| 209 | return mBuilder.build(); |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Rewrite actions to use LINC OF optical extensions. |
| 214 | * |
| 215 | * @param actions original actions |
| 216 | * @return rewritten actions |
| 217 | */ |
| 218 | private List<OFAction> rewriteActions(List<OFAction> actions) { |
| 219 | List<OFAction> newActions = new LinkedList<>(); |
| 220 | |
| 221 | for (OFAction action : actions) { |
| 222 | if (!(action instanceof OFActionSetField)) { |
| 223 | newActions.add(action); |
| 224 | continue; |
| 225 | } |
| 226 | |
| 227 | OFActionSetField sf = (OFActionSetField) action; |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 228 | if (!(sf.getField() instanceof OFOxmExpOchSigId)) { |
Marc De Leenheer | c2999f3 | 2015-11-20 15:52:16 -0800 | [diff] [blame] | 229 | newActions.add(action); |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 230 | continue; |
Marc De Leenheer | c2999f3 | 2015-11-20 15:52:16 -0800 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | OFOxmExpOchSigId oxm = (OFOxmExpOchSigId) sf.getField(); |
| 234 | CircuitSignalID signalId = oxm.getValue(); |
| 235 | |
| 236 | newActions.add( |
| 237 | factory().actions().circuit(factory().oxms().ochSigid(signalId))); |
| 238 | } |
| 239 | |
| 240 | return newActions; |
| 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public void sendMsg(OFMessage msg) { |
| 245 | // Ignore everything but flow mods and stat requests |
| 246 | if (!(msg instanceof OFFlowMod || msg instanceof OFFlowStatsRequest)) { |
| 247 | super.sendMsg(msg); |
| 248 | return; |
| 249 | } |
| 250 | |
| 251 | Match newMatch; |
| 252 | OFMessage newMsg = null; |
| 253 | |
| 254 | if (msg instanceof OFFlowStatsRequest) { |
| 255 | // Rewrite match only |
| 256 | OFFlowStatsRequest fsr = (OFFlowStatsRequest) msg; |
| 257 | newMatch = rewriteMatch(fsr.getMatch()); |
| 258 | newMsg = fsr.createBuilder().setMatch(newMatch).build(); |
| 259 | } else if (msg instanceof OFFlowMod) { |
| 260 | // Rewrite match and actions |
| 261 | OFFlowMod fm = (OFFlowMod) msg; |
| 262 | newMatch = rewriteMatch(fm.getMatch()); |
| 263 | List<OFAction> actions = rewriteActions(fm.getActions()); |
Marc De Leenheer | c2999f3 | 2015-11-20 15:52:16 -0800 | [diff] [blame] | 264 | newMsg = fm.createBuilder().setMatch(newMatch).setActions(actions).build(); |
| 265 | } |
| 266 | |
| 267 | super.sendMsg(newMsg); |
| 268 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 269 | |
| 270 | @Override |
| 271 | public Boolean supportNxRole() { |
| 272 | return false; |
| 273 | } |
| 274 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 275 | @Override |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 276 | public Device.Type deviceType() { |
| 277 | return Device.Type.ROADM; |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 280 | /** |
| 281 | * Checks if given port is also part of the regular port desc stats, i.e., is the port a tap port. |
| 282 | * |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 283 | * @param port given port number |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 284 | * @return true if the port is a tap (OCh), false otherwise (OMS port) |
| 285 | */ |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 286 | private boolean isOChPort(long port) { |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 287 | for (OFPortDescStatsReply reply : this.ports) { |
| 288 | for (OFPortDesc p : reply.getEntries()) { |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 289 | if (p.getPortNo().getPortNumber() == port) { |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 290 | return true; |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | return false; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Creates an OpenFlow optical port based on the given port and transport type. |
| 300 | * |
| 301 | * @param port OpenFlow optical port |
| 302 | * @param type transport type |
| 303 | * @return OpenFlow optical port |
| 304 | */ |
| 305 | private OFPortOptical createOpticalPort(OFPortOptical port, short type) { |
| 306 | List<OFPortDescPropOpticalTransport> descList = new ArrayList<>(port.getDesc().size()); |
| 307 | |
| 308 | for (OFPortDescPropOpticalTransport desc : port.getDesc()) { |
| 309 | OFPortDescPropOpticalTransport newDesc = desc.createBuilder() |
| 310 | .setType(desc.getType()) |
| 311 | .setPortSignalType(type) |
| 312 | .setPortType(desc.getPortType()) |
| 313 | .setReserved(desc.getReserved()) |
| 314 | .build(); |
| 315 | descList.add(newDesc); |
| 316 | } |
| 317 | |
| 318 | OFPortOptical newPort = port.createBuilder() |
| 319 | .setConfig(port.getConfig()) |
| 320 | .setDesc(descList) |
| 321 | .setHwAddr(port.getHwAddr()) |
| 322 | .setName(port.getName()) |
| 323 | .setPortNo(port.getPortNo()) |
| 324 | .setState(port.getState()) |
| 325 | .build(); |
| 326 | |
| 327 | return newPort; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * Builds list of OFPortOptical ports based on the multi-part circuit ports reply. |
| 332 | * |
| 333 | * Ensure the optical transport port's signal type is configured correctly. |
| 334 | * |
| 335 | * @param wPorts OF reply with circuit ports |
| 336 | */ |
| 337 | private void createOpticalPortList(OFCircuitPortsReply wPorts) { |
| 338 | opticalPorts = new ArrayList<>(wPorts.getEntries().size()); |
| 339 | |
| 340 | for (OFPortOptical p : wPorts.getEntries()) { |
| 341 | short signalType; |
| 342 | |
| 343 | // FIXME: use constants once loxi has full optical extensions |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 344 | if (isOChPort(p.getPortNo().getPortNumber())) { |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 345 | signalType = 5; // OCH port |
| 346 | } else { |
| 347 | signalType = 2; // OMS port |
| 348 | } |
| 349 | |
| 350 | opticalPorts.add(createOpticalPort(p, signalType)); |
| 351 | } |
| 352 | } |
| 353 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 354 | @Override |
| 355 | public List<? extends OFObject> getPortsOf(PortDescPropertyType type) { |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 356 | if (!type.equals(PortDescPropertyType.OPTICAL_TRANSPORT)) { |
| 357 | return Collections.EMPTY_LIST; |
| 358 | } |
| 359 | |
| 360 | return opticalPorts; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | @Override |
| 364 | public Set<PortDescPropertyType> getPortTypes() { |
| 365 | return ImmutableSet.of(PortDescPropertyType.OPTICAL_TRANSPORT); |
| 366 | } |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 367 | |
| 368 | @Override |
| 369 | public SortedSet<OchSignal> queryLambdas(PortNumber port) { |
| 370 | // OCh ports don't have lambdas |
| 371 | if (isOChPort(port.toLong())) { |
| 372 | return Collections.emptySortedSet(); |
| 373 | } |
| 374 | |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 375 | // OMS ports expose 80 fixed grid lambdas of 50GHz width, centered around the ITU-T center frequency 193.1 THz. |
| 376 | Supplier<SortedSet<OchSignal>> supplier = () -> new TreeSet<>(new DefaultOchSignalComparator()); |
| 377 | return IntStream.range(0, LAMBDA_COUNT) |
| 378 | .mapToObj(x -> new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, x - (LAMBDA_COUNT / 2), 4)) |
| 379 | .collect(Collectors.toCollection(supplier)); |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 380 | } |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 381 | } |