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.ParametrizedConvertor;
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;
30 * Converts port mod, port status and port description MD-SAL messages to OF library data
35 * VersionConvertorData data = new VersionConvertorData(version);
36 * Optional<PortModInput> ofPort = ConvertorManager.getInstance().convert(salPort, data);
40 public class PortConvertor implements ParametrizedConvertor<Port, PortModInput, VersionConvertorData> {
43 * Create default empty port mod input
44 * Use this method, if result from convertor is empty.
46 * @param version Openflow version
47 * @return default empty port mod input
49 public static PortModInput defaultResult(short version) {
50 return new PortModInputBuilder()
55 private static PortConfig maskPortConfigFields(
56 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
57 Boolean portDown = configData.isPORTDOWN();
58 Boolean noRecv = configData.isNORECV();
59 Boolean noFwd = configData.isNOFWD();
60 Boolean noPacketIn = configData.isNOPACKETIN();
62 return new PortConfig(noFwd, noPacketIn, noRecv, portDown);
66 private static PortConfigV10 maskPortConfigV10Fields(
67 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
68 Boolean portDown = configData.isPORTDOWN();
69 Boolean noRecv = configData.isNORECV();
70 Boolean noFwd = configData.isNOFWD();
71 Boolean noPacketIn = configData.isNOPACKETIN();
73 return new PortConfigV10(false, noFwd, noPacketIn, noRecv, true, true, portDown);
77 private static PortFeatures getPortFeatures(
78 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
80 return new PortFeatures(salPortFeatures.isHundredGbFd(), salPortFeatures.isHundredMbFd(),
81 salPortFeatures.isHundredMbHd(), salPortFeatures.isTenGbFd(), salPortFeatures.isTenMbFd(),
82 salPortFeatures.isTenMbHd(), salPortFeatures.isOneGbFd(), salPortFeatures.isOneGbHd(),
83 salPortFeatures.isOneTbFd(), salPortFeatures.isFortyGbFd(), salPortFeatures.isAutoeng(),
84 salPortFeatures.isCopper(), salPortFeatures.isFiber(), salPortFeatures.isOther(),
85 salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
88 private static PortFeaturesV10 getPortFeaturesV10(
89 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
91 return new PortFeaturesV10(salPortFeatures.isHundredMbFd(), salPortFeatures.isHundredMbHd(), salPortFeatures.isTenGbFd(), salPortFeatures.isTenMbFd(), salPortFeatures.isTenMbHd(),
92 salPortFeatures.isOneGbFd(), salPortFeatures.isOneGbHd(), salPortFeatures.isAutoeng(), salPortFeatures.isCopper(), salPortFeatures.isFiber(),
93 salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
97 * This method is called as a reply to OFPMP_PORT_DESCRIPTION
100 * @param source FlowCapablePort
101 * @param version openflow version
105 static Ports toPortDesc(
106 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.FlowCapablePort source,
109 PortsBuilder oFPortDescDataBuilder = new PortsBuilder();
111 oFPortDescDataBuilder.setPortNo(
112 OpenflowPortsUtil.getProtocolPortNumber(OpenflowVersion.get(version), source.getPortNumber())); // portNO
114 oFPortDescDataBuilder.setHwAddr(source.getHardwareAddress());
115 oFPortDescDataBuilder.setName(source.getName());
117 PortConfig config = maskPortConfigFields(source.getConfiguration());
119 oFPortDescDataBuilder.setConfig(config);
121 PortState portState = getPortState(source.getState());
123 oFPortDescDataBuilder.setState(portState);
124 oFPortDescDataBuilder.setCurrentFeatures(getPortFeatures(source.getCurrentFeature()));
125 oFPortDescDataBuilder.setAdvertisedFeatures(getPortFeatures(source.getAdvertisedFeatures()));
126 oFPortDescDataBuilder.setSupportedFeatures(getPortFeatures(source.getSupported()));
127 oFPortDescDataBuilder.setPeerFeatures(getPortFeatures(source.getPeerFeatures()));
128 oFPortDescDataBuilder.setCurrSpeed(source.getCurrentSpeed());
129 oFPortDescDataBuilder.setMaxSpeed(source.getMaximumSpeed());
131 return oFPortDescDataBuilder.build();
135 private static PortState getPortState(
136 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortState state) {
138 boolean isLinkDown = state.isLinkDown();
139 boolean isBlocked = state.isBlocked();
140 boolean isLive = state.isLive();
142 return new PortState(isLinkDown, isBlocked, isLive);
147 public Class<?> getType() {
152 public PortModInput convert(Port source, VersionConvertorData data) {
153 PortConfig config = maskPortConfigFields(source.getConfiguration());
154 PortConfigV10 configV10 = maskPortConfigV10Fields(source.getConfiguration());
156 PortModInputBuilder portModInputBuilder = new PortModInputBuilder();
157 portModInputBuilder.setAdvertise(getPortFeatures(source.getAdvertisedFeatures()));
158 portModInputBuilder.setPortNo(new PortNumber(
159 OpenflowPortsUtil.getProtocolPortNumber(OpenflowVersion.get(data.getVersion()), source.getPortNumber())));
161 portModInputBuilder.setConfig(config);
162 portModInputBuilder.setMask(config);
164 portModInputBuilder.setHwAddress(new MacAddress(source.getHardwareAddress()));
166 portModInputBuilder.setVersion(data.getVersion());
168 portModInputBuilder.setConfigV10(configV10);
169 portModInputBuilder.setMaskV10(configV10);
170 portModInputBuilder.setAdvertiseV10(getPortFeaturesV10(source.getAdvertisedFeatures()));
171 return portModInputBuilder.build();