Fix Bug 271
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / translator / FeaturesV10ToNodeConnectorUpdatedTranslator.java
1 package org.opendaylight.openflowplugin.openflow.md.core.translator;
2
3 import java.math.BigInteger;
4 import java.util.Collections;
5 import java.util.List;
6 import java.util.concurrent.CopyOnWriteArrayList;
7
8 import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator;
9 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
10 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
11 import org.opendaylight.openflowplugin.openflow.md.util.PortTranslatorUtil;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class FeaturesV10ToNodeConnectorUpdatedTranslator implements IMDMessageTranslator<OfHeader, List<DataObject>> {
20     protected static final Logger LOG = LoggerFactory
21             .getLogger(FeaturesV10ToNodeConnectorUpdatedTranslator.class);
22
23     @Override
24     public List<DataObject> translate(SwitchConnectionDistinguisher cookie,
25             SessionContext sc, OfHeader msg) {
26         if(msg instanceof GetFeaturesOutput) {        
27             GetFeaturesOutput features = (GetFeaturesOutput) msg;
28             List<DataObject> list = new CopyOnWriteArrayList<DataObject>();
29             BigInteger datapathId = sc.getFeatures().getDatapathId();
30             if( features.getPhyPort() != null ) {
31                 for (PhyPort port : features.getPhyPort()) {
32                     list.add(PortTranslatorUtil.translatePort(msg.getVersion(), datapathId, port.getPortNo(), port));
33                 }
34             }
35             return list;
36         } else {
37             // TODO - Do something smarter than returning null if translation fails... what Exception should we throw here?
38             return Collections.emptyList();
39         }
40     }
41 }