copyright header added
[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
15 import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator;
16 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
17 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
18 import org.opendaylight.openflowplugin.openflow.md.util.PortTranslatorUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
22 import org.opendaylight.yangtools.yang.binding.DataObject;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 public class FeaturesV10ToNodeConnectorUpdatedTranslator implements IMDMessageTranslator<OfHeader, List<DataObject>> {
27     protected static final Logger LOG = LoggerFactory
28             .getLogger(FeaturesV10ToNodeConnectorUpdatedTranslator.class);
29
30     @Override
31     public List<DataObject> translate(SwitchConnectionDistinguisher cookie,
32             SessionContext sc, OfHeader msg) {
33         if(msg instanceof GetFeaturesOutput) {        
34             GetFeaturesOutput features = (GetFeaturesOutput) msg;
35             List<DataObject> list = new CopyOnWriteArrayList<DataObject>();
36             BigInteger datapathId = sc.getFeatures().getDatapathId();
37             if( features.getPhyPort() != null ) {
38                 for (PhyPort port : features.getPhyPort()) {
39                     list.add(PortTranslatorUtil.translatePort(msg.getVersion(), datapathId, port.getPortNo(), port));
40                 }
41             }
42             return list;
43         } else {
44             // TODO - Do something smarter than returning null if translation fails... what Exception should we throw here?
45             return Collections.emptyList();
46         }
47     }
48 }