diff options
Diffstat (limited to 'framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker')
7 files changed, 0 insertions, 998 deletions
diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/CalientFiberSwitchHandshaker.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/CalientFiberSwitchHandshaker.java deleted file mode 100644 index 270008f3..00000000 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/CalientFiberSwitchHandshaker.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.driver.handshaker; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import org.onlab.util.Spectrum; -import org.onosproject.net.ChannelSpacing; -import org.onosproject.net.DefaultOchSignalComparator; -import org.onosproject.net.Device; -import org.onosproject.net.GridType; -import org.onosproject.net.OchSignal; -import org.onosproject.net.PortNumber; -import org.onosproject.net.behaviour.LambdaQuery; -import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; -import org.onosproject.openflow.controller.PortDescPropertyType; -import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; -import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted; -import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted; -import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted; -import org.projectfloodlight.openflow.protocol.OFCalientFlowStatsRequest; -import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsEntry; -import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsReply; -import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsRequest; -import org.projectfloodlight.openflow.protocol.OFFlowStatsRequest; -import org.projectfloodlight.openflow.protocol.OFMessage; -import org.projectfloodlight.openflow.protocol.OFObject; -import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; -import org.projectfloodlight.openflow.protocol.OFStatsRequest; -import org.projectfloodlight.openflow.protocol.OFType; -import org.projectfloodlight.openflow.types.OFPort; -import org.projectfloodlight.openflow.types.TableId; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -/** - * Driver for Calient S160 Optical Circuit Switch. Untested on Calient S320 but probably works ok. - * - * Driver implements custom handshaker, and rewrites flow stats as expected by the device. Port stats are currently - * not supported. - * - * The device consists of OMS ports only, and each port exposes lambda resources covering the whole - * usable optical spectrum (U to O band, see {@link Spectrum} for spectrum definitions). - */ -public class CalientFiberSwitchHandshaker - extends AbstractOpenFlowSwitch - implements OpenFlowOpticalSwitch, LambdaQuery { - - private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false); - private List<OFCalientPortDescStatsEntry> fiberPorts = new ArrayList<>(); - - - @Override - public Boolean supportNxRole() { - return false; - } - - @Override - public void startDriverHandshake() { - log.warn("Starting driver handshake for sw {}", getStringId()); - if (startDriverHandshakeCalled) { - throw new SwitchDriverSubHandshakeAlreadyStarted(); - } - startDriverHandshakeCalled = true; - try { - sendHandshakeOFExperimenterPortDescRequest(); - } catch (IOException e) { - log.error("Exception while sending experimenter port desc:", e.getMessage()); - e.printStackTrace(); - } - - } - - private void sendHandshakeOFExperimenterPortDescRequest() throws IOException { - // send multi part message for port description for optical switches - OFCalientPortDescStatsRequest portsRequest = factory() - .buildCalientPortDescStatsRequest() - .build(); - log.warn("Sending experimenter port description message {}", - portsRequest.toString()); - this.sendHandshakeMessage(portsRequest); - } - - @Override - public boolean isDriverHandshakeComplete() { - return driverHandshakeComplete.get(); - } - - @Override - public void processDriverHandshakeMessage(OFMessage m) { - if (!startDriverHandshakeCalled) { - throw new SwitchDriverSubHandshakeNotStarted(); - } - if (driverHandshakeComplete.get()) { - throw new SwitchDriverSubHandshakeCompleted(m); - } - - switch (m.getType()) { - case BARRIER_REPLY: - break; - case ERROR: - log.error("Switch Error {} {}", getStringId(), m); - break; - case FEATURES_REPLY: - break; - case FLOW_REMOVED: - break; - case GET_ASYNC_REPLY: - break; - case PACKET_IN: - break; - case PORT_STATUS: - break; - case QUEUE_GET_CONFIG_REPLY: - break; - case ROLE_REPLY: - break; - case STATS_REPLY: - log.warn("Received port desc reply"); - OFCalientPortDescStatsReply descStatsReply = (OFCalientPortDescStatsReply) m; - fiberPorts.addAll(descStatsReply.getPortDesc()); - // Multi-part message - if (!descStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { - driverHandshakeComplete.set(true); - } - break; - default: - log.warn("Received message {} during switch-driver " + - "subhandshake " + "from switch {} ... " + - "Ignoring message", m, - getStringId()); - - } - } - - @Override - public Device.Type deviceType() { - return Device.Type.FIBER_SWITCH; - } - - @Override - public List<? extends OFObject> getPortsOf(PortDescPropertyType type) { - return ImmutableList.copyOf(fiberPorts); - } - - @Override - public Set<PortDescPropertyType> getPortTypes() { - return ImmutableSet.of(PortDescPropertyType.OPTICAL_TRANSPORT); - } - - @Override - public final void sendMsg(OFMessage m) { - OFMessage newMsg = m; - - if (m.getType() == OFType.STATS_REQUEST) { - OFStatsRequest sr = (OFStatsRequest) m; - log.debug("Rebuilding stats request type {}", sr.getStatsType()); - switch (sr.getStatsType()) { - case FLOW: - OFCalientFlowStatsRequest request = this.factory().buildCalientFlowStatsRequest() - .setCookie(((OFFlowStatsRequest) sr).getCookie()) - .setCookieMask(((OFFlowStatsRequest) sr).getCookieMask()) - .setMatch(this.factory().matchWildcardAll()) - .setOutGroup(((OFFlowStatsRequest) sr).getOutGroup().getGroupNumber()) - .setOutPort(OFPort.ANY) - .setTableId(TableId.ALL) - .setXid(sr.getXid()) - .setFlags(sr.getFlags()) - .build(); - newMsg = request; - break; - case PORT: - // TODO - break; - default: - break; - } - } - - super.sendMsg(newMsg); - } - - @Override - public SortedSet<OchSignal> queryLambdas(PortNumber port) { - // S160 data sheet - // Wavelength range: 1260 - 1630 nm - long startSpacingMultiplier = Spectrum.U_BAND_MIN.subtract(Spectrum.CENTER_FREQUENCY).asHz() / - ChannelSpacing.CHL_12P5GHZ.frequency().asHz(); - long stopSpacingMultiplier = Spectrum.O_BAND_MAX.subtract(Spectrum.CENTER_FREQUENCY).asHz() / - ChannelSpacing.CHL_12P5GHZ.frequency().asHz(); - List<OchSignal> lambdas = IntStream.rangeClosed((int) startSpacingMultiplier, (int) stopSpacingMultiplier) - .mapToObj(x -> new OchSignal(GridType.FLEX, ChannelSpacing.CHL_12P5GHZ, x, 1)) - .collect(Collectors.toList()); - - SortedSet<OchSignal> result = new TreeSet<>(new DefaultOchSignalComparator()); - result.addAll(lambdas); - - return result; - } -} diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/CorsaSwitchHandshaker.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/CorsaSwitchHandshaker.java deleted file mode 100644 index 376b3985..00000000 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/CorsaSwitchHandshaker.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.driver.handshaker; - -import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; -import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted; -import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted; -import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted; -import org.projectfloodlight.openflow.protocol.OFBarrierRequest; -import org.projectfloodlight.openflow.protocol.OFFlowMod; -import org.projectfloodlight.openflow.protocol.OFMessage; -import org.projectfloodlight.openflow.protocol.OFType; -import org.projectfloodlight.openflow.types.OFGroup; -import org.projectfloodlight.openflow.types.TableId; - -import java.util.Collections; -import java.util.concurrent.atomic.AtomicBoolean; - - -/** - * Corsa switch handshaker. - */ -public class CorsaSwitchHandshaker extends AbstractOpenFlowSwitch { - - private AtomicBoolean handshakeComplete = new AtomicBoolean(false); - - private int barrierXid; - - - @Override - public Boolean supportNxRole() { - return false; - } - - @Override - public void startDriverHandshake() { - if (startDriverHandshakeCalled) { - throw new SwitchDriverSubHandshakeAlreadyStarted(); - } - startDriverHandshakeCalled = true; - OFFlowMod fm = factory().buildFlowDelete() - .setTableId(TableId.ALL) - .setOutGroup(OFGroup.ANY) - .build(); - - sendMsg(Collections.singletonList(fm)); - - barrierXid = getNextTransactionId(); - OFBarrierRequest barrier = factory().buildBarrierRequest() - .setXid(barrierXid).build(); - - - sendHandshakeMessage(barrier); - - } - - @Override - public boolean isDriverHandshakeComplete() { - if (!startDriverHandshakeCalled) { - throw new SwitchDriverSubHandshakeAlreadyStarted(); - } - return handshakeComplete.get(); - } - - @Override - public void processDriverHandshakeMessage(OFMessage m) { - if (!startDriverHandshakeCalled) { - throw new SwitchDriverSubHandshakeNotStarted(); - } - if (handshakeComplete.get()) { - throw new SwitchDriverSubHandshakeCompleted(m); - } - if (m.getType() == OFType.BARRIER_REPLY && - m.getXid() == barrierXid) { - handshakeComplete.set(true); - } - } - -} diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/DefaultSwitchHandshaker.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/DefaultSwitchHandshaker.java deleted file mode 100644 index fb789440..00000000 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/DefaultSwitchHandshaker.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.driver.handshaker; - -import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; -import org.projectfloodlight.openflow.protocol.OFFlowAdd; -import org.projectfloodlight.openflow.protocol.OFMessage; -import org.projectfloodlight.openflow.protocol.OFPortDesc; -import org.projectfloodlight.openflow.protocol.OFVersion; - -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -/** - * Default driver to fallback on if no other driver is available. - */ -public class DefaultSwitchHandshaker extends AbstractOpenFlowSwitch { - - private static final int LOWEST_PRIORITY = 0; - - @Override - public Boolean supportNxRole() { - return false; - } - - @Override - public void startDriverHandshake() { - if (factory().getVersion() == OFVersion.OF_10) { - OFFlowAdd.Builder fmBuilder = factory().buildFlowAdd(); - fmBuilder.setPriority(LOWEST_PRIORITY); - sendHandshakeMessage(fmBuilder.build()); - } - } - - @Override - public void processDriverHandshakeMessage(OFMessage m) {} - - @Override - public boolean isDriverHandshakeComplete() { - return true; - } - - @Override - public List<OFPortDesc> getPorts() { - if (this.factory().getVersion() == OFVersion.OF_10) { - return Collections.unmodifiableList(features.getPorts()); - } else { - return Collections.unmodifiableList( - ports.stream().flatMap(p -> p.getEntries().stream()) - .collect(Collectors.toList())); - } - } -} diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/NiciraSwitchHandshaker.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/NiciraSwitchHandshaker.java deleted file mode 100644 index 4f61361f..00000000 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/NiciraSwitchHandshaker.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.driver.handshaker; - -import org.projectfloodlight.openflow.protocol.OFVersion; - -/** - * Default driver to fallback on if no other driver is available. - */ -public class NiciraSwitchHandshaker extends DefaultSwitchHandshaker { - - @Override - public Boolean supportNxRole() { - if (this.factory().getVersion() == OFVersion.OF_10) { - return true; - } - return false; - } - -} diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/OFOpticalSwitch13.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/OFOpticalSwitch13.java deleted file mode 100644 index 5c6ce360..00000000 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/OFOpticalSwitch13.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.driver.handshaker; - -import org.projectfloodlight.openflow.protocol.OFExpPort; -import org.projectfloodlight.openflow.protocol.OFExpPortDescReply; -import org.projectfloodlight.openflow.protocol.OFExpPortDescRequest; -import org.projectfloodlight.openflow.protocol.OFMessage; -import org.projectfloodlight.openflow.protocol.OFPortDesc; -import org.projectfloodlight.openflow.protocol.OFStatsReply; -import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; -import org.projectfloodlight.openflow.protocol.OFStatsType; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; - -import org.onosproject.net.Device; -import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; -import org.onosproject.openflow.controller.PortDescPropertyType; -import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; -import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted; -import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted; -import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted; -import org.projectfloodlight.openflow.protocol.OFObject; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - - -/** - * Open Flow Optical Switch handshaker - for Open Flow 13. - */ -public class OFOpticalSwitch13 extends AbstractOpenFlowSwitch implements OpenFlowOpticalSwitch { - - private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false); - private List<OFExpPort> expPortDes = new ArrayList<>(); - - @Override - public Boolean supportNxRole() { - return false; - } - - @Override - public void startDriverHandshake() { - log.info("Starting driver handshake for sw {}", getStringId()); - if (startDriverHandshakeCalled) { - throw new SwitchDriverSubHandshakeAlreadyStarted(); - } - startDriverHandshakeCalled = true; - - log.debug("sendHandshakeOFExperimenterPortDescRequest for sw {}", getStringId()); - - try { - sendHandshakeOFExperimenterPortDescRequest(); - } catch (IOException e) { - log.error("Failed to send handshaker message OFExperimenterPortDescRequestfor sw {}, {}", - getStringId(), e.getMessage()); - e.printStackTrace(); - } - } - - @Override - public void processDriverHandshakeMessage(OFMessage m) { - if (!startDriverHandshakeCalled) { - throw new SwitchDriverSubHandshakeNotStarted(); - } - if (driverHandshakeComplete.get()) { - throw new SwitchDriverSubHandshakeCompleted(m); - } - - log.debug("processDriverHandshakeMessage for sw {}", getStringId()); - - switch (m.getType()) { - case STATS_REPLY: // multipart message is reported as STAT - processOFMultipartReply((OFStatsReply) m); - break; - default: - log.warn("Received message {} during switch-driver " + - "subhandshake " + "from switch {} ... " + - "Ignoring message", m, - getStringId()); - } - } - - private void processOFMultipartReply(OFStatsReply stats) { - log.debug("Received message {} during switch-driver " + - "subhandshake " + "from switch {} ... " + - stats, - getStringId()); - - if (stats.getStatsType() == OFStatsType.EXPERIMENTER) { - try { - OFExpPortDescReply expPortDescReply = (OFExpPortDescReply) stats; - expPortDes.addAll(expPortDescReply.getEntries()); - if (!expPortDescReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { - driverHandshakeComplete.set(true); - return; - } - } catch (ClassCastException e) { - log.error("Unexspected Experimenter Multipart message type {} " - , stats.getClass().getName()); - } - } - } - - - @Override - public boolean isDriverHandshakeComplete() { - return driverHandshakeComplete.get(); - } - - private void sendHandshakeOFExperimenterPortDescRequest() throws - IOException { - - OFExpPortDescRequest preq = factory() - .buildExpPortDescRequest() - .setXid(getNextTransactionId()) - .build(); - - log.debug("Sending experimented port description " + - "message " + - "{}", - preq.toString()); - - this.sendHandshakeMessage(preq); - } - - @Override - public Device.Type deviceType() { - String hwDesc = hardwareDescription(); - switch (hwDesc) { - case "Optical-ROADM": - return Device.Type.ROADM; - case "Optical-OTN": - return Device.Type.OTN; - default: - log.error("Unsupported hardwareDescription {}", hwDesc); - return Device.Type.OTHER; - } - } - - /* - * OduClt ports are reported as regular ETH ports. - */ - @Override - public List<OFPortDesc> getPorts() { - return ImmutableList.copyOf( - ports.stream().flatMap(p -> p.getEntries().stream()) - .collect(Collectors.toList())); - } - - @Override - public List<? extends OFObject> getPortsOf(PortDescPropertyType type) { - return ImmutableList.copyOf(expPortDes); - } - - @Override - public Set<PortDescPropertyType> getPortTypes() { - return ImmutableSet.of(PortDescPropertyType.OPTICAL_TRANSPORT); - } - -} diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/OfOpticalSwitchImplLinc13.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/OfOpticalSwitchImplLinc13.java deleted file mode 100644 index 23378e95..00000000 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/OfOpticalSwitchImplLinc13.java +++ /dev/null @@ -1,385 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.driver.handshaker; - -import com.google.common.collect.ImmutableSet; -import org.onosproject.net.ChannelSpacing; -import org.onosproject.net.DefaultOchSignalComparator; -import org.onosproject.net.Device; -import org.onosproject.net.GridType; -import org.onosproject.net.OchSignal; -import org.onosproject.net.PortNumber; -import org.onosproject.net.behaviour.LambdaQuery; -import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; -import org.onosproject.openflow.controller.PortDescPropertyType; -import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; -import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted; -import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted; -import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted; -import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus; -import org.projectfloodlight.openflow.protocol.OFCircuitPortsReply; -import org.projectfloodlight.openflow.protocol.OFCircuitPortsRequest; -import org.projectfloodlight.openflow.protocol.OFFlowMod; -import org.projectfloodlight.openflow.protocol.OFFlowStatsRequest; -import org.projectfloodlight.openflow.protocol.OFMessage; -import org.projectfloodlight.openflow.protocol.OFObject; -import org.projectfloodlight.openflow.protocol.OFPortDesc; -import org.projectfloodlight.openflow.protocol.OFPortDescPropOpticalTransport; -import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; -import org.projectfloodlight.openflow.protocol.OFPortOptical; -import org.projectfloodlight.openflow.protocol.OFStatsReply; -import org.projectfloodlight.openflow.protocol.OFStatsType; -import org.projectfloodlight.openflow.protocol.action.OFAction; -import org.projectfloodlight.openflow.protocol.action.OFActionSetField; -import org.projectfloodlight.openflow.protocol.match.Match; -import org.projectfloodlight.openflow.protocol.match.MatchField; -import org.projectfloodlight.openflow.protocol.oxm.OFOxmExpOchSigId; -import org.projectfloodlight.openflow.types.CircuitSignalID; -import org.projectfloodlight.openflow.types.U8; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -/** - * LINC-OE Optical Emulator switch class. - * - * The LINC ROADM emulator exposes two types of ports: OCh ports connect to ports in the packet layer, - * while OMS ports connect to an OMS port on a neighbouring ROADM. - * - * LINC sends the tap ports (OCh for our purposes) in the regular port desc stats reply, - * while it sends *all* ports (both tap and WDM ports, i.e., OCh and OMS) in the experimenter port desc stats reply. - * - * As LINC implements custom OF optical extensions (in contrast to the final standard as specified in - * ONF TS-022 (March 15, 2015), we need to rewrite flow stat requests and flow mods in {@link #sendMsg(OFMessage)}. - * - * LINC exposes OchSignal resources: 80 lambdas of 50 GHz around ITU-T G.694.1 center frequency 193.1 GHz. - * - */ -public class OfOpticalSwitchImplLinc13 - extends AbstractOpenFlowSwitch implements OpenFlowOpticalSwitch, LambdaQuery { - - private static final int LAMBDA_COUNT = 80; - private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false); - private long barrierXidToWaitFor = -1; - - private List<OFPortOptical> opticalPorts; - - @Override - public void startDriverHandshake() { - log.warn("Starting driver handshake for sw {}", getStringId()); - if (startDriverHandshakeCalled) { - throw new SwitchDriverSubHandshakeAlreadyStarted(); - } - startDriverHandshakeCalled = true; - try { - sendHandshakeOFExperimenterPortDescRequest(); - } catch (IOException e) { - log.error("LINC-OE exception while sending experimenter port desc:", - e.getMessage()); - e.printStackTrace(); - } - } - - @Override - public boolean isDriverHandshakeComplete() { - return driverHandshakeComplete.get(); - } - - @Override - public void processDriverHandshakeMessage(OFMessage m) { - if (!startDriverHandshakeCalled) { - throw new SwitchDriverSubHandshakeNotStarted(); - } - if (driverHandshakeComplete.get()) { - throw new SwitchDriverSubHandshakeCompleted(m); - } - - switch (m.getType()) { - case BARRIER_REPLY: - if (m.getXid() == barrierXidToWaitFor) { - log.debug("LINC-OE Received barrier response"); - } - break; - case ERROR: - log.error("Switch {} Error {}", getStringId(), m); - break; - case FEATURES_REPLY: - break; - case FLOW_REMOVED: - break; - case GET_ASYNC_REPLY: - break; - case PACKET_IN: - break; - case PORT_STATUS: - log.warn("****LINC-OE Port Status {} {}", getStringId(), m); - processOFPortStatus((OFCircuitPortStatus) m); - break; - case QUEUE_GET_CONFIG_REPLY: - break; - case ROLE_REPLY: - break; - case STATS_REPLY: - OFStatsReply stats = (OFStatsReply) m; - if (stats.getStatsType() == OFStatsType.EXPERIMENTER) { - log.warn("LINC-OE : Received stats reply message {}", m); - createOpticalPortList((OFCircuitPortsReply) m); - driverHandshakeComplete.set(true); - } - break; - default: - log.warn("Received message {} during switch-driver " + - "subhandshake " + "from switch {} ... " + - "Ignoring message", m, - getStringId()); - - } - } - - public void processOFPortStatus(OFCircuitPortStatus ps) { - log.debug("LINC-OE ..OF Port Status :", ps); - } - - private void sendHandshakeOFExperimenterPortDescRequest() throws - IOException { - // send multi part message for port description for optical switches - OFCircuitPortsRequest circuitPortsRequest = factory() - .buildCircuitPortsRequest().setXid(getNextTransactionId()) - .build(); - log.warn("LINC-OE : Sending experimented circuit port stats " + - "message " + - "{}", - circuitPortsRequest.toString()); - this.sendHandshakeMessage(circuitPortsRequest); - } - - @Override - /** - * Returns a list of standard (Ethernet) ports. - * - * @return List of ports - */ - public List<OFPortDesc> getPorts() { - return Collections.EMPTY_LIST; - } - - /** - * Rewrite match object to use LINC OF optical extensions. - * - * @param match original match - * @return rewritten match - */ - private Match rewriteMatch(Match match) { - Match.Builder mBuilder = factory().buildMatch(); - for (MatchField mf : match.getMatchFields()) { - if (mf == MatchField.EXP_OCH_SIG_ID) { - mBuilder.setExact(MatchField.OCH_SIGID, (CircuitSignalID) match.get(mf)); - continue; - } - if (mf == MatchField.EXP_OCH_SIGTYPE) { - mBuilder.setExact(MatchField.OCH_SIGTYPE, (U8) match.get(mf)); - continue; - } - mBuilder.setExact(mf, match.get(mf)); - } - - return mBuilder.build(); - } - - /** - * Rewrite actions to use LINC OF optical extensions. - * - * @param actions original actions - * @return rewritten actions - */ - private List<OFAction> rewriteActions(List<OFAction> actions) { - List<OFAction> newActions = new LinkedList<>(); - - for (OFAction action : actions) { - if (!(action instanceof OFActionSetField)) { - newActions.add(action); - continue; - } - - OFActionSetField sf = (OFActionSetField) action; - if (!(sf instanceof OFOxmExpOchSigId)) { - newActions.add(action); - } - - OFOxmExpOchSigId oxm = (OFOxmExpOchSigId) sf.getField(); - CircuitSignalID signalId = oxm.getValue(); - - newActions.add( - factory().actions().circuit(factory().oxms().ochSigid(signalId))); - } - - return newActions; - } - - @Override - public void sendMsg(OFMessage msg) { - // Ignore everything but flow mods and stat requests - if (!(msg instanceof OFFlowMod || msg instanceof OFFlowStatsRequest)) { - super.sendMsg(msg); - return; - } - - Match newMatch; - OFMessage newMsg = null; - - if (msg instanceof OFFlowStatsRequest) { - // Rewrite match only - OFFlowStatsRequest fsr = (OFFlowStatsRequest) msg; - newMatch = rewriteMatch(fsr.getMatch()); - newMsg = fsr.createBuilder().setMatch(newMatch).build(); - } else if (msg instanceof OFFlowMod) { - // Rewrite match and actions - OFFlowMod fm = (OFFlowMod) msg; - newMatch = rewriteMatch(fm.getMatch()); - List<OFAction> actions = rewriteActions(fm.getActions()); - - newMsg = fm.createBuilder().setMatch(newMatch).setActions(actions).build(); - } - - super.sendMsg(newMsg); - } - - @Override - public Boolean supportNxRole() { - return false; - } - - @Override - public Device.Type deviceType() { - return Device.Type.ROADM; - } - - /** - * Checks if given port is also part of the regular port desc stats, i.e., is the port a tap port. - * - * @param port given port number - * @return true if the port is a tap (OCh), false otherwise (OMS port) - */ - private boolean isOChPort(long port) { - for (OFPortDescStatsReply reply : this.ports) { - for (OFPortDesc p : reply.getEntries()) { - if (p.getPortNo().getPortNumber() == port) { - return true; - } - } - } - - return false; - } - - /** - * Creates an OpenFlow optical port based on the given port and transport type. - * - * @param port OpenFlow optical port - * @param type transport type - * @return OpenFlow optical port - */ - private OFPortOptical createOpticalPort(OFPortOptical port, short type) { - List<OFPortDescPropOpticalTransport> descList = new ArrayList<>(port.getDesc().size()); - - for (OFPortDescPropOpticalTransport desc : port.getDesc()) { - OFPortDescPropOpticalTransport newDesc = desc.createBuilder() - .setType(desc.getType()) - .setPortSignalType(type) - .setPortType(desc.getPortType()) - .setReserved(desc.getReserved()) - .build(); - descList.add(newDesc); - } - - OFPortOptical newPort = port.createBuilder() - .setConfig(port.getConfig()) - .setDesc(descList) - .setHwAddr(port.getHwAddr()) - .setName(port.getName()) - .setPortNo(port.getPortNo()) - .setState(port.getState()) - .build(); - - return newPort; - } - - /** - * Builds list of OFPortOptical ports based on the multi-part circuit ports reply. - * - * Ensure the optical transport port's signal type is configured correctly. - * - * @param wPorts OF reply with circuit ports - */ - private void createOpticalPortList(OFCircuitPortsReply wPorts) { - opticalPorts = new ArrayList<>(wPorts.getEntries().size()); - - for (OFPortOptical p : wPorts.getEntries()) { - short signalType; - - // FIXME: use constants once loxi has full optical extensions - if (isOChPort(p.getPortNo().getPortNumber())) { - signalType = 5; // OCH port - } else { - signalType = 2; // OMS port - } - - opticalPorts.add(createOpticalPort(p, signalType)); - } - } - - @Override - public List<? extends OFObject> getPortsOf(PortDescPropertyType type) { - if (!type.equals(PortDescPropertyType.OPTICAL_TRANSPORT)) { - return Collections.EMPTY_LIST; - } - - return opticalPorts; - } - - @Override - public Set<PortDescPropertyType> getPortTypes() { - return ImmutableSet.of(PortDescPropertyType.OPTICAL_TRANSPORT); - } - - @Override - public SortedSet<OchSignal> queryLambdas(PortNumber port) { - // OCh ports don't have lambdas - if (isOChPort(port.toLong())) { - return Collections.emptySortedSet(); - } - - // OMS ports expose 80 lambdas of 50GHz width, centered around the ITU-T center frequency. - // We report these with a spacing of 12.5 GHz. - List<OchSignal> lambdas = IntStream.range(0, LAMBDA_COUNT) - .mapToObj(x -> new OchSignal(GridType.FLEX, ChannelSpacing.CHL_12P5GHZ, x - (LAMBDA_COUNT / 2), 1)) - .collect(Collectors.toList()); - - SortedSet<OchSignal> result = new TreeSet<>(new DefaultOchSignalComparator()); - result.addAll(lambdas); - - return result; - } -} diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/package-info.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/package-info.java deleted file mode 100644 index 754309eb..00000000 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Implementations of the OpenFlow handshake driver behaviours. - */ -package org.onosproject.driver.handshaker;
\ No newline at end of file |