26ce35bb8e2bd4a70e576a0104668def6f0e5cf4
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / translator / MultipartReplyTableFeaturesToTableUpdatedTranslator.java
1 /**
2  * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. 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  * Contributor: hema.gopalkrishnan@ericsson.com
9  */
10 package org.opendaylight.openflowplugin.openflow.md.core.translator;
11
12 import java.math.BigInteger;
13 import java.util.Collections;
14 import java.util.List;
15 import java.util.concurrent.CopyOnWriteArrayList;
16
17 import org.opendaylight.openflowplugin.api.openflow.md.core.IMDMessageTranslator;
18 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
19 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesReplyConvertor;
20 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
21 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesCase;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.MultipartReplyTableFeatures;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.TableUpdatedBuilder;
31 import org.opendaylight.yangtools.yang.binding.DataObject;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 public class MultipartReplyTableFeaturesToTableUpdatedTranslator implements
36                 IMDMessageTranslator<OfHeader, List<DataObject>> {
37
38         protected static final Logger LOG = LoggerFactory
39             .getLogger(MultipartReplyTableFeaturesToTableUpdatedTranslator.class);
40         
41         @Override
42         public List<DataObject> translate(SwitchConnectionDistinguisher cookie,
43                         SessionContext sc, OfHeader msg) {
44                 
45                                 
46                 if(msg instanceof MultipartReply && ((MultipartReply) msg).getType() == MultipartType.OFPMPTABLEFEATURES) {
47                         LOG.debug("MultipartReply Being translated to TableUpdated " );
48                         MultipartReplyMessage mpReply = (MultipartReplyMessage)msg;
49                         
50             List<DataObject> listDataObject = new CopyOnWriteArrayList<DataObject>();
51             
52             TableUpdatedBuilder message = new TableUpdatedBuilder() ;
53             message.setNode((new NodeRef(InventoryDataServiceUtil.identifierFromDatapathId(sc.getFeatures()
54                     .getDatapathId()))));
55             message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE());
56             message.setTransactionId(new TransactionId(new BigInteger(mpReply.getXid().toString() ))) ;
57             MultipartReplyTableFeaturesCase caseBody = (MultipartReplyTableFeaturesCase) mpReply.getMultipartReplyBody();
58             MultipartReplyTableFeatures body = caseBody.getMultipartReplyTableFeatures();
59             message.setTableFeatures(TableFeaturesReplyConvertor.toTableFeaturesReply(body)) ;
60             listDataObject.add( message.build()) ;
61             
62             return listDataObject ;
63             
64                 }
65                 return Collections.emptyList();
66                 
67         }
68         
69 }
70