2 * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 * Contributor: hema.gopalkrishnan@ericsson.com
10 package org.opendaylight.openflowplugin.openflow.md.core.translator;
12 import java.math.BigInteger;
13 import java.util.Collections;
14 import java.util.List;
15 import java.util.concurrent.CopyOnWriteArrayList;
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.api.openflow.md.core.session.SessionContext;
20 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesReplyConvertor;
21 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.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;
35 public class MultipartReplyTableFeaturesToTableUpdatedTranslator implements
36 IMDMessageTranslator<OfHeader, List<DataObject>> {
38 protected static final Logger LOG = LoggerFactory
39 .getLogger(MultipartReplyTableFeaturesToTableUpdatedTranslator.class);
42 public List<DataObject> translate(SwitchConnectionDistinguisher cookie,
43 SessionContext sc, OfHeader msg) {
46 if(msg instanceof MultipartReply && ((MultipartReply) msg).getType() == MultipartType.OFPMPTABLEFEATURES) {
47 LOG.debug("MultipartReply Being translated to TableUpdated " );
48 MultipartReplyMessage mpReply = (MultipartReplyMessage)msg;
50 List<DataObject> listDataObject = new CopyOnWriteArrayList<DataObject>();
52 TableUpdatedBuilder message = new TableUpdatedBuilder() ;
53 message.setNode((new NodeRef(InventoryDataServiceUtil.identifierFromDatapathId(sc.getFeatures()
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()) ;
62 return listDataObject ;
65 return Collections.emptyList();