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