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
8 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
10 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
11 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
21 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;
22 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;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * @author esssuuu This convertor class is used for Port Mod,port status and
28 * port description messages,decodes SAL and encodes to OF Data
31 public final class PortConvertor {
32 private static final Logger LOG = LoggerFactory.getLogger(PortConvertor.class);
34 private PortConvertor() {
39 * This method is used by PORT_MOD_MESSAGE
41 * @param source source port
42 * @param version openflow version
43 * @return port mod input
46 public static PortModInput toPortModInput(
47 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port source,
51 PortConfig config = maskPortConfigFields(source.getConfiguration());
52 PortConfigV10 configV10 = maskPortConfigV10Fields(source.getConfiguration());
54 PortModInputBuilder portModInputBuilder = new PortModInputBuilder();
55 portModInputBuilder.setAdvertise(getPortFeatures(source.getAdvertisedFeatures()));
56 portModInputBuilder.setPortNo(new PortNumber(
57 OpenflowPortsUtil.getProtocolPortNumber(OpenflowVersion.get(version), source.getPortNumber())));
59 portModInputBuilder.setConfig(config);
60 portModInputBuilder.setMask(config);
62 portModInputBuilder.setHwAddress(new MacAddress(source.getHardwareAddress()));
64 portModInputBuilder.setVersion(version);
66 portModInputBuilder.setConfigV10(configV10);
67 portModInputBuilder.setMaskV10(configV10);
68 portModInputBuilder.setAdvertiseV10(getPortFeaturesV10(source.getAdvertisedFeatures()));
69 return portModInputBuilder.build();
73 private static PortConfig maskPortConfigFields(
74 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
75 Boolean portDown = configData.isPORTDOWN();
76 Boolean noRecv = configData.isNORECV();
77 Boolean noFwd = configData.isNOFWD();
78 Boolean noPacketIn = configData.isNOPACKETIN();
80 return new PortConfig(noFwd, noPacketIn, noRecv, portDown);
84 private static PortConfigV10 maskPortConfigV10Fields(
85 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
86 Boolean portDown = configData.isPORTDOWN();
87 Boolean noRecv = configData.isNORECV();
88 Boolean noFwd = configData.isNOFWD();
89 Boolean noPacketIn = configData.isNOPACKETIN();
91 return new PortConfigV10(false, noFwd, noPacketIn, noRecv, true, true, portDown);
94 private static PortFeatures getPortFeatures(
95 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
97 return new PortFeatures(salPortFeatures.isHundredGbFd(), salPortFeatures.isHundredMbFd(),
98 salPortFeatures.isHundredMbHd(), salPortFeatures.isTenGbFd(), salPortFeatures.isTenMbFd(),
99 salPortFeatures.isTenMbHd(), salPortFeatures.isOneGbFd(), salPortFeatures.isOneGbHd(),
100 salPortFeatures.isOneTbFd(), salPortFeatures.isFortyGbFd(), salPortFeatures.isAutoeng(),
101 salPortFeatures.isCopper(), salPortFeatures.isFiber(), salPortFeatures.isOther(),
102 salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
105 private static PortFeaturesV10 getPortFeaturesV10(
106 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
108 return new PortFeaturesV10(salPortFeatures.isHundredMbFd(), salPortFeatures.isHundredMbHd(), salPortFeatures.isTenGbFd(), salPortFeatures.isTenMbFd(), salPortFeatures.isTenMbHd(),
109 salPortFeatures.isOneGbFd(), salPortFeatures.isOneGbHd(), salPortFeatures.isAutoeng(), salPortFeatures.isCopper(), salPortFeatures.isFiber(),
110 salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
115 * This method is called as a reply to OFPMP_PORT_DESCRIPTION
119 * @param source FlowCapablePort
120 * @param version openflow version
123 public static Ports toPortDesc(
124 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.FlowCapablePort source,
127 PortConfig config = null;
128 PortState portState = null;
130 PortsBuilder oFPortDescDataBuilder = new PortsBuilder();
132 oFPortDescDataBuilder.setPortNo(
133 OpenflowPortsUtil.getProtocolPortNumber(OpenflowVersion.get(version), source.getPortNumber())); // portNO
135 oFPortDescDataBuilder.setHwAddr(source.getHardwareAddress());
136 oFPortDescDataBuilder.setName(source.getName());
138 config = maskPortConfigFields(source.getConfiguration());
140 oFPortDescDataBuilder.setConfig(config);
142 portState = getPortState(source.getState());
144 oFPortDescDataBuilder.setState(portState);
145 oFPortDescDataBuilder.setCurrentFeatures(getPortFeatures(source.getCurrentFeature()));
146 oFPortDescDataBuilder.setAdvertisedFeatures(getPortFeatures(source.getAdvertisedFeatures()));
147 oFPortDescDataBuilder.setSupportedFeatures(getPortFeatures(source.getSupported()));
148 oFPortDescDataBuilder.setPeerFeatures(getPortFeatures(source.getPeerFeatures()));
149 oFPortDescDataBuilder.setCurrSpeed(source.getCurrentSpeed());
150 oFPortDescDataBuilder.setMaxSpeed(source.getMaximumSpeed());
152 return oFPortDescDataBuilder.build();
156 private static PortState getPortState(
157 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortState state) {
159 boolean isLinkDown = state.isLinkDown();
160 boolean isBlocked = state.isBlocked();
161 boolean isLive = state.isLive();
163 return new PortState(isLinkDown, isBlocked, isLive);