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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.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
45 public static PortModInput toPortModInput(
46 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port source,
50 PortConfig config = maskPortConfigFields(source.getConfiguration());
51 PortConfigV10 configV10 = maskPortConfigV10Fields(source.getConfiguration());
53 PortModInputBuilder portModInputBuilder = new PortModInputBuilder();
54 portModInputBuilder.setAdvertise(getPortFeatures(source.getAdvertisedFeatures()));
55 portModInputBuilder.setPortNo(new PortNumber(source.getPortNumber()));
57 portModInputBuilder.setConfig(config);
58 portModInputBuilder.setMask(config);
60 portModInputBuilder.setHwAddress(new MacAddress(source.getHardwareAddress()));
62 portModInputBuilder.setVersion(version);
64 portModInputBuilder.setConfigV10(configV10);
65 portModInputBuilder.setMaskV10(configV10);
66 portModInputBuilder.setAdvertiseV10(getPortFeaturesV10(source.getAdvertisedFeatures()));
67 return portModInputBuilder.build();
71 private static PortConfig maskPortConfigFields(
72 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
73 Boolean portDown = configData.isPORTDOWN();
74 Boolean noRecv = configData.isNORECV();
75 Boolean noFwd = configData.isNOFWD();
76 Boolean noPacketIn = configData.isNOPACKETIN();
78 return new PortConfig(noFwd, noPacketIn, noRecv, portDown);
82 private static PortConfigV10 maskPortConfigV10Fields(
83 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
84 Boolean portDown = configData.isPORTDOWN();
85 Boolean noRecv = configData.isNORECV();
86 Boolean noFwd = configData.isNOFWD();
87 Boolean noPacketIn = configData.isNOPACKETIN();
89 return new PortConfigV10(false, noFwd, noPacketIn, noRecv, true, true, portDown);
92 private static PortFeatures getPortFeatures(
93 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
95 return new PortFeatures(salPortFeatures.isHundredGbFd(), salPortFeatures.isHundredMbFd(),
96 salPortFeatures.isHundredMbHd(), salPortFeatures.isTenGbFd(), salPortFeatures.isTenMbFd(),
97 salPortFeatures.isTenMbHd(), salPortFeatures.isOneGbFd(), salPortFeatures.isOneGbHd(),
98 salPortFeatures.isOneTbFd(), salPortFeatures.isFortyGbFd(), salPortFeatures.isAutoeng(),
99 salPortFeatures.isCopper(), salPortFeatures.isFiber(), salPortFeatures.isOther(),
100 salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
103 private static PortFeaturesV10 getPortFeaturesV10(
104 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
106 return new PortFeaturesV10(salPortFeatures.isHundredMbFd(), salPortFeatures.isHundredMbHd(), salPortFeatures.isTenGbFd(), salPortFeatures.isTenMbFd(), salPortFeatures.isTenMbHd(),
107 salPortFeatures.isOneGbFd(), salPortFeatures.isOneGbHd(), salPortFeatures.isAutoeng(), salPortFeatures.isCopper(), salPortFeatures.isFiber(),
108 salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
113 * This method is called as a reply to OFPMP_PORT_DESCRIPTION
118 * :SAL FlowCapablePort
121 public static Ports toPortDesc(
122 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.FlowCapablePort source) {
124 PortConfig config = null;
125 PortState portState = null;
127 PortsBuilder OFPortDescDataBuilder = new PortsBuilder();
128 OFPortDescDataBuilder.setPortNo(source.getPortNumber()); // portNO
130 OFPortDescDataBuilder.setHwAddr(source.getHardwareAddress());
131 OFPortDescDataBuilder.setName(source.getName());
133 config = maskPortConfigFields(source.getConfiguration());
135 OFPortDescDataBuilder.setConfig(config);
137 portState = getPortState(source.getState());
139 OFPortDescDataBuilder.setState(portState);
140 OFPortDescDataBuilder.setCurrentFeatures(getPortFeatures(source.getCurrentFeature()));
141 OFPortDescDataBuilder.setAdvertisedFeatures(getPortFeatures(source.getAdvertisedFeatures()));
142 OFPortDescDataBuilder.setSupportedFeatures(getPortFeatures(source.getSupported()));
143 OFPortDescDataBuilder.setPeerFeatures(getPortFeatures(source.getPeerFeatures()));
144 OFPortDescDataBuilder.setCurrSpeed(source.getCurrentSpeed());
145 OFPortDescDataBuilder.setMaxSpeed(source.getMaximumSpeed());
147 return OFPortDescDataBuilder.build();
151 private static PortState getPortState(
152 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortState state) {
154 boolean isLinkDown = state.isLinkDown();
155 boolean isBlocked = state.isBlocked();
156 boolean isLive = state.isLive();
158 return new PortState(isLinkDown, isBlocked, isLive);