2 * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
11 import com.google.common.annotations.VisibleForTesting;
12 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
14 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor;
15 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
16 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.Ports;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.PortsBuilder;
28 import org.opendaylight.yangtools.yang.binding.DataContainer;
31 * Converts port mod, port status and port description MD-SAL messages to OF library data
36 * VersionConvertorData data = new VersionConvertorData(version);
37 * Optional<PortModInput> ofPort = ConvertorManager.getInstance().convert(salPort, data);
41 public class PortConvertor implements Convertor<Port, PortModInput, VersionConvertorData> {
44 * Create default empty port mod input
45 * Use this method, if result from convertor is empty.
47 * @param version Openflow version
48 * @return default empty port mod input
50 public static PortModInput defaultResult(short version) {
51 return new PortModInputBuilder()
56 private static PortConfig maskPortConfigFields(
57 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
58 Boolean portDown = configData.isPORTDOWN();
59 Boolean noRecv = configData.isNORECV();
60 Boolean noFwd = configData.isNOFWD();
61 Boolean noPacketIn = configData.isNOPACKETIN();
63 return new PortConfig(noFwd, noPacketIn, noRecv, portDown);
67 private static PortConfigV10 maskPortConfigV10Fields(
68 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
69 Boolean portDown = configData.isPORTDOWN();
70 Boolean noRecv = configData.isNORECV();
71 Boolean noFwd = configData.isNOFWD();
72 Boolean noPacketIn = configData.isNOPACKETIN();
74 return new PortConfigV10(false, noFwd, noPacketIn, noRecv, true, true, portDown);
78 private static PortFeatures getPortFeatures(
79 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
81 return new PortFeatures(salPortFeatures.isHundredGbFd(), salPortFeatures.isHundredMbFd(),
82 salPortFeatures.isHundredMbHd(), salPortFeatures.isTenGbFd(), salPortFeatures.isTenMbFd(),
83 salPortFeatures.isTenMbHd(), salPortFeatures.isOneGbFd(), salPortFeatures.isOneGbHd(),
84 salPortFeatures.isOneTbFd(), salPortFeatures.isFortyGbFd(), salPortFeatures.isAutoeng(),
85 salPortFeatures.isCopper(), salPortFeatures.isFiber(), salPortFeatures.isOther(),
86 salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
89 private static PortFeaturesV10 getPortFeaturesV10(
90 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
92 return new PortFeaturesV10(salPortFeatures.isHundredMbFd(), salPortFeatures.isHundredMbHd(), salPortFeatures.isTenGbFd(), salPortFeatures.isTenMbFd(), salPortFeatures.isTenMbHd(),
93 salPortFeatures.isOneGbFd(), salPortFeatures.isOneGbHd(), salPortFeatures.isAutoeng(), salPortFeatures.isCopper(), salPortFeatures.isFiber(),
94 salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
98 * This method is called as a reply to OFPMP_PORT_DESCRIPTION
101 * @param source FlowCapablePort
102 * @param version openflow version
106 static Ports toPortDesc(
107 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.FlowCapablePort source,
110 PortsBuilder oFPortDescDataBuilder = new PortsBuilder();
112 oFPortDescDataBuilder.setPortNo(
113 OpenflowPortsUtil.getProtocolPortNumber(OpenflowVersion.get(version), source.getPortNumber())); // portNO
115 oFPortDescDataBuilder.setHwAddr(source.getHardwareAddress());
116 oFPortDescDataBuilder.setName(source.getName());
118 PortConfig config = maskPortConfigFields(source.getConfiguration());
120 oFPortDescDataBuilder.setConfig(config);
122 PortState portState = getPortState(source.getState());
124 oFPortDescDataBuilder.setState(portState);
125 oFPortDescDataBuilder.setCurrentFeatures(getPortFeatures(source.getCurrentFeature()));
126 oFPortDescDataBuilder.setAdvertisedFeatures(getPortFeatures(source.getAdvertisedFeatures()));
127 oFPortDescDataBuilder.setSupportedFeatures(getPortFeatures(source.getSupported()));
128 oFPortDescDataBuilder.setPeerFeatures(getPortFeatures(source.getPeerFeatures()));
129 oFPortDescDataBuilder.setCurrSpeed(source.getCurrentSpeed());
130 oFPortDescDataBuilder.setMaxSpeed(source.getMaximumSpeed());
132 return oFPortDescDataBuilder.build();
136 private static PortState getPortState(
137 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortState state) {
139 boolean isLinkDown = state.isLinkDown();
140 boolean isBlocked = state.isBlocked();
141 boolean isLive = state.isLive();
143 return new PortState(isLinkDown, isBlocked, isLive);
148 public Class<? extends DataContainer> getType() {
153 public PortModInput convert(Port source, VersionConvertorData data) {
154 PortConfig config = maskPortConfigFields(source.getConfiguration());
155 PortConfigV10 configV10 = maskPortConfigV10Fields(source.getConfiguration());
157 PortModInputBuilder portModInputBuilder = new PortModInputBuilder();
158 portModInputBuilder.setAdvertise(getPortFeatures(source.getAdvertisedFeatures()));
159 portModInputBuilder.setPortNo(new PortNumber(
160 OpenflowPortsUtil.getProtocolPortNumber(OpenflowVersion.get(data.getVersion()), source.getPortNumber())));
162 portModInputBuilder.setConfig(config);
163 portModInputBuilder.setMask(config);
165 portModInputBuilder.setHwAddress(new MacAddress(source.getHardwareAddress()));
167 portModInputBuilder.setVersion(data.getVersion());
169 portModInputBuilder.setConfigV10(configV10);
170 portModInputBuilder.setMaskV10(configV10);
171 portModInputBuilder.setAdvertiseV10(getPortFeaturesV10(source.getAdvertisedFeatures()));
172 return portModInputBuilder.build();