Merge "BUG-2091: notification NodeRemoved and processing queue"
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / translator / NotificationPlainTranslator.java
1 /**
2  * Copyright (c) 2014 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
14 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
15 import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator;
16 import org.opendaylight.openflowplugin.openflow.md.core.NotificationQueueWrapper;
17 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
19 import org.opendaylight.yangtools.yang.binding.DataObject;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 import com.google.common.collect.Lists;
24
25 /**
26  * 
27  */
28 public class NotificationPlainTranslator implements IMDMessageTranslator<OfHeader, List<DataObject>> {
29     
30     private static final Logger LOG = LoggerFactory
31             .getLogger(NotificationPlainTranslator.class);
32     
33     @Override
34     public List<DataObject> translate(SwitchConnectionDistinguisher cookie,
35             SessionContext sc, OfHeader msg) {
36         List<DataObject> results = null;
37         
38         if(msg instanceof NotificationQueueWrapper) {
39             NotificationQueueWrapper wrappedNotification = (NotificationQueueWrapper) msg;
40             BigInteger datapathId = sc.getFeatures().getDatapathId();
41             Short version = wrappedNotification.getVersion();
42             LOG.debug("NotificationQueueWrapper: version {}  dataPathId {} notification {}", version, datapathId, wrappedNotification.getImplementedInterface());
43             results = Lists.newArrayList((DataObject) wrappedNotification.getNotification());
44         } else {
45             // TODO - Do something smarter than returning null if translation fails... what Exception should we throw here?
46             results = Collections.emptyList();
47         }
48         return results;
49     }
50
51 }