1 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
3 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
4 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
5 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
6 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
10 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;
11 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;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
16 * @author esssuuu This convertor class is used for Port Mod,port status and
17 * port description messages,decodes SAL and encodes to OF Data
20 public final class PortConvertor {
21 private static final Logger log = LoggerFactory.getLogger(PortConvertor.class);
23 private PortConvertor() {
28 * This method is used by PORT_MOD_MESSAGE
34 public static PortModInput toPortModInput(
35 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port source,
39 PortConfig config = null;
41 PortModInputBuilder portModInputBuilder = new PortModInputBuilder();
42 portModInputBuilder.setAdvertise(getPortFeatures(source.getAdvertisedFeatures()));
43 portModInputBuilder.setPortNo(new PortNumber(source.getPortNumber()));
44 maskPortConfigFields(source.getConfiguration(), config);
45 portModInputBuilder.setConfig(config);
46 portModInputBuilder.setHwAddress(new MacAddress(source.getHardwareAddress()));
48 maskPortConfigFields(source.getMask(), config);
49 portModInputBuilder.setMask(config);
50 portModInputBuilder.setVersion(version);
51 return portModInputBuilder.build();
55 private static void maskPortConfigFields(
56 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData,
58 Boolean portDown = false;
59 Boolean noRecv = false;
60 Boolean noFwd = false;
61 Boolean noPacketIn = false;
62 if (configData.isNOFWD())
64 if (configData.isNOPACKETIN())
66 if (configData.isNORECV())
68 if (configData.isPORTDOWN())
71 config = new PortConfig(noFwd, noPacketIn, noRecv, portDown);
75 private static PortFeatures getPortFeatures(
76 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures salPortFeatures) {
78 return new PortFeatures(salPortFeatures.is_100gbFd(), salPortFeatures.is_100mbFd(),
79 salPortFeatures.is_100mbHd(), salPortFeatures.is_10gbFd(), salPortFeatures.is_10mbFd(),
80 salPortFeatures.is_10mbHd(), salPortFeatures.is_1gbFd(), salPortFeatures.is_1gbHd(),
81 salPortFeatures.is_1tbFd(), salPortFeatures.is_40gbFd(), salPortFeatures.isAutoeng(),
82 salPortFeatures.isCopper(), salPortFeatures.isFiber(), salPortFeatures.isOther(),
83 salPortFeatures.isPause(), salPortFeatures.isPauseAsym());
87 * This method is called as a reply to OFPMP_PORT_DESCRIPTION
92 * :SAL FlowCapablePort
95 public static Ports toPortDesc(
96 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.FlowCapablePort source) {
98 PortConfig config = null;
99 PortState portState = null;
101 PortsBuilder OFPortDescDataBuilder = new PortsBuilder();
102 OFPortDescDataBuilder.setPortNo(source.getPortNumber()); // portNO
104 OFPortDescDataBuilder.setHwAddr(source.getHardwareAddress());
105 OFPortDescDataBuilder.setName(source.getName());
107 maskPortConfigFields(source.getConfiguration(), config);
109 OFPortDescDataBuilder.setConfig(config);
111 getPortState(source.getState(), portState);
112 OFPortDescDataBuilder.setState(portState);
113 OFPortDescDataBuilder.setCurrentFeatures(getPortFeatures(source.getCurrentFeature()));
114 OFPortDescDataBuilder.setAdvertisedFeatures(getPortFeatures(source.getAdvertisedFeatures()));
115 OFPortDescDataBuilder.setSupportedFeatures(getPortFeatures(source.getSupported()));
116 OFPortDescDataBuilder.setPeerFeatures(getPortFeatures(source.getPeerFeatures()));
117 OFPortDescDataBuilder.setCurrSpeed(source.getCurrentSpeed());
118 OFPortDescDataBuilder.setMaxSpeed(source.getMaximumSpeed());
120 return OFPortDescDataBuilder.build();
124 private static void getPortState(
125 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortState state, PortState portState) {
127 boolean isLinkDown = false;// (0),
128 boolean isBlocked = false; // (1),
129 boolean isLive = false; // (2);
131 if (state.getIntValue() == 0) {
133 } else if (state.getIntValue() == 1) {
135 } else if (state.getIntValue() == 2) {
138 portState = new PortState(isLinkDown, isBlocked, isLive);