2 * Copyright (c) 2015 Cisco Systems, Inc. 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.impl.translator;
10 import java.util.Collections;
11 import org.opendaylight.openflowplugin.api.OFConstants;
12 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
13 import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
14 import org.opendaylight.openflowplugin.openflow.md.util.PortTranslatorUtil;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortReason;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
27 public class PortUpdateTranslator implements MessageTranslator<PortGrouping, FlowCapableNodeConnector> {
28 private static final Logger logger = LoggerFactory.getLogger(PortUpdateTranslator.class);
31 public FlowCapableNodeConnector translate(final PortGrouping input,
32 final DeviceInfo deviceInfo, final Object connectionDistinguisher) {
33 final FlowCapableNodeConnectorBuilder builder = new FlowCapableNodeConnectorBuilder();
35 if (deviceInfo.getVersion() == OFConstants.OFP_VERSION_1_0) {
36 builder.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(input.getAdvertisedFeaturesV10()));
37 builder.setConfiguration(PortTranslatorUtil.translatePortConfig(input.getConfigV10()));
38 builder.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(input.getCurrentFeaturesV10()));
39 builder.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(input.getPeerFeaturesV10()));
40 builder.setState(PortTranslatorUtil.translatePortState(input.getStateV10()));
41 builder.setSupported(PortTranslatorUtil.translatePortFeatures(input.getSupportedFeaturesV10()));
42 } else if (deviceInfo.getVersion() == OFConstants.OFP_VERSION_1_3) {
43 builder.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(input.getAdvertisedFeatures()));
44 builder.setConfiguration(PortTranslatorUtil.translatePortConfig(input.getConfig()));
45 builder.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(input.getCurrentFeatures()));
46 builder.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(input.getPeerFeatures()));
47 builder.setState(PortTranslatorUtil.translatePortState(input.getState()));
48 builder.setSupported(PortTranslatorUtil.translatePortFeatures(input.getSupportedFeatures()));
49 builder.setQueue(Collections.<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue>emptyList());
51 if (input instanceof PortStatusMessage) {
52 if (((PortStatusMessage) input).getReason() != null) {
53 builder.setReason(PortReason.forValue(((PortStatusMessage) input).getReason().getIntValue()));
55 logger.debug("PortStatus Message has reason as null");
58 builder.setCurrentSpeed(input.getCurrSpeed());
59 builder.setHardwareAddress(input.getHwAddr());
60 builder.setMaximumSpeed(input.getMaxSpeed());
61 builder.setName(input.getName());
62 builder.setPortNumber(new PortNumberUni(input.getPortNo()));
64 return builder.build();