6c35a2a50ec6692c994ef4fe15d72e3329549289
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / translator / PortUpdateTranslator.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowplugin.impl.translator;
9
10 import java.util.Collections;
11 import org.opendaylight.openflowplugin.api.OFConstants;
12 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
13 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
14 import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
15 import org.opendaylight.openflowplugin.openflow.md.util.PortTranslatorUtil;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder;
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
21 /**
22  * @author tkubas
23  */
24 public class PortUpdateTranslator implements MessageTranslator<PortGrouping, FlowCapableNodeConnector> {
25
26     @Override
27     public FlowCapableNodeConnector translate(final PortGrouping input,
28                                               final DeviceState deviceState, final Object connectionDistinguisher) {
29         final FlowCapableNodeConnectorBuilder builder = new FlowCapableNodeConnectorBuilder();
30         //OF1.0
31         if (deviceState.getVersion() == OFConstants.OFP_VERSION_1_0) {
32             builder.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(input.getAdvertisedFeaturesV10()));
33             builder.setConfiguration(PortTranslatorUtil.translatePortConfig(input.getConfigV10()));
34             builder.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(input.getCurrentFeaturesV10()));
35             builder.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(input.getPeerFeaturesV10()));
36             builder.setState(PortTranslatorUtil.translatePortState(input.getStateV10()));
37             builder.setSupported(PortTranslatorUtil.translatePortFeatures(input.getSupportedFeaturesV10()));
38         } else if (deviceState.getVersion() == OFConstants.OFP_VERSION_1_3) {
39             builder.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(input.getAdvertisedFeatures()));
40             builder.setConfiguration(PortTranslatorUtil.translatePortConfig(input.getConfig()));
41             builder.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(input.getCurrentFeatures()));
42             builder.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(input.getPeerFeatures()));
43             builder.setState(PortTranslatorUtil.translatePortState(input.getState()));
44             builder.setSupported(PortTranslatorUtil.translatePortFeatures(input.getSupportedFeatures()));
45             builder.setQueue(Collections.<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue>emptyList());
46         }
47         builder.setCurrentSpeed(input.getCurrSpeed());
48         builder.setHardwareAddress(input.getHwAddr());
49         builder.setMaximumSpeed(input.getMaxSpeed());
50         builder.setName(input.getName());
51         builder.setPortNumber(new PortNumberUni(input.getPortNo()));
52
53         return builder.build();
54     }
55 }