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 * Contributor: usha.m.s@ericsson.com
10 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
12 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
13 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowVersion;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
23 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;
24 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;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * @author esssuuu This convertor class is used for Port Mod,port status and
30 * port description messages,decodes SAL and encodes to OF Data
33 public final class PortConvertor {
34 private static final Logger log = LoggerFactory.getLogger(PortConvertor.class);
36 private PortConvertor() {
41 * This method is used by PORT_MOD_MESSAGE
47 public static PortModInput toPortModInput(
48 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port source,
52 PortConfig config = maskPortConfigFields(source.getConfiguration());
53 PortConfigV10 configV10 = maskPortConfigV10Fields(source.getConfiguration());
55 PortModInputBuilder portModInputBuilder = new PortModInputBuilder();
56 portModInputBuilder.setAdvertise(getPortFeatures(source.getAdvertisedFeatures()));
57 portModInputBuilder.setPortNo(new PortNumber(
58 OpenflowPortsUtil.getProtocolPortNumber(OpenflowVersion.get(version), source.getPortNumber())));
60 portModInputBuilder.setConfig(config);
61 portModInputBuilder.setMask(config);
63 portModInputBuilder.setHwAddress(new MacAddress(source.getHardwareAddress()));
65 portModInputBuilder.setVersion(version);
67 portModInputBuilder.setConfigV10(configV10);
68 portModInputBuilder.setMaskV10(configV10);
69 portModInputBuilder.setAdvertiseV10(getPortFeaturesV10(source.getAdvertisedFeatures()));
70 return portModInputBuilder.build();
74 private static PortConfig maskPortConfigFields(
75 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
76 Boolean portDown = configData.isPORTDOWN();
77 Boolean noRecv = configData.isNORECV();
78 Boolean noFwd = configData.isNOFWD();
79 Boolean noPacketIn = configData.isNOPACKETIN();
81 return new PortConfig(noFwd, noPacketIn, noRecv, portDown);
85 private static PortConfigV10 maskPortConfigV10Fields(
86 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
87 Boolean portDown = configData.isPORTDOWN();
88 Boolean noRecv = configData.isNORECV();
89 Boolean noFwd = configData.isNOFWD();
90 Boolean noPacketIn = configData.isNOPACKETIN();
92 return new PortConfigV10(false, noFwd, noPacketIn, noRecv, true, true, portDown);
95 private static PortFeatures getPortFeatures(
96 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
98 return new PortFeatures(salPortFeatures.isHundredGbFd(), salPortFeatures.isHundredMbFd(),
99 salPortFeatures.isHundredMbHd(), salPortFeatures.isTenGbFd(), salPortFeatures.isTenMbFd(),
100 salPortFeatures.isTenMbHd(), salPortFeatures.isOneGbFd(), salPortFeatures.isOneGbHd(),
101 salPortFeatures.isOneTbFd(), salPortFeatures.isFortyGbFd(), salPortFeatures.isAutoeng(),
102 salPortFeatures.isCopper(), salPortFeatures.isFiber(), salPortFeatures.isOther(),
103 salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
106 private static PortFeaturesV10 getPortFeaturesV10(
107 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
109 return new PortFeaturesV10(salPortFeatures.isHundredMbFd(), salPortFeatures.isHundredMbHd(), salPortFeatures.isTenGbFd(), salPortFeatures.isTenMbFd(), salPortFeatures.isTenMbHd(),
110 salPortFeatures.isOneGbFd(), salPortFeatures.isOneGbHd(), salPortFeatures.isAutoeng(), salPortFeatures.isCopper(), salPortFeatures.isFiber(),
111 salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
116 * This method is called as a reply to OFPMP_PORT_DESCRIPTION
121 * :SAL FlowCapablePort
124 public static Ports toPortDesc(
125 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.FlowCapablePort source,
128 PortConfig config = null;
129 PortState portState = null;
131 PortsBuilder OFPortDescDataBuilder = new PortsBuilder();
133 OFPortDescDataBuilder.setPortNo(
134 OpenflowPortsUtil.getProtocolPortNumber(OpenflowVersion.get(version), source.getPortNumber())); // portNO
136 OFPortDescDataBuilder.setHwAddr(source.getHardwareAddress());
137 OFPortDescDataBuilder.setName(source.getName());
139 config = maskPortConfigFields(source.getConfiguration());
141 OFPortDescDataBuilder.setConfig(config);
143 portState = getPortState(source.getState());
145 OFPortDescDataBuilder.setState(portState);
146 OFPortDescDataBuilder.setCurrentFeatures(getPortFeatures(source.getCurrentFeature()));
147 OFPortDescDataBuilder.setAdvertisedFeatures(getPortFeatures(source.getAdvertisedFeatures()));
148 OFPortDescDataBuilder.setSupportedFeatures(getPortFeatures(source.getSupported()));
149 OFPortDescDataBuilder.setPeerFeatures(getPortFeatures(source.getPeerFeatures()));
150 OFPortDescDataBuilder.setCurrSpeed(source.getCurrentSpeed());
151 OFPortDescDataBuilder.setMaxSpeed(source.getMaximumSpeed());
153 return OFPortDescDataBuilder.build();
157 private static PortState getPortState(
158 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortState state) {
160 boolean isLinkDown = state.isLinkDown();
161 boolean isBlocked = state.isBlocked();
162 boolean isLive = state.isLive();
164 return new PortState(isLinkDown, isBlocked, isLive);