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
9 package org.opendaylight.openflowplugin.openflow.md.core.translator;
11 import java.math.BigInteger;
12 import java.util.Collections;
13 import java.util.List;
14 import java.util.Optional;
15 import java.util.concurrent.CopyOnWriteArrayList;
16 import org.opendaylight.openflowplugin.api.openflow.md.core.IMDMessageTranslator;
17 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
18 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
19 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
20 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
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.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
32 import org.opendaylight.yangtools.yang.binding.DataObject;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class MultipartReplyTableFeaturesToTableUpdatedTranslator implements
37 IMDMessageTranslator<OfHeader, List<DataObject>> {
39 private static final Logger LOG = LoggerFactory
40 .getLogger(MultipartReplyTableFeaturesToTableUpdatedTranslator.class);
41 private final ConvertorExecutor convertorExecutor;
43 public MultipartReplyTableFeaturesToTableUpdatedTranslator(ConvertorExecutor convertorExecutor) {
44 this.convertorExecutor = convertorExecutor;
48 public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sc, OfHeader msg) {
49 if (msg instanceof MultipartReply && ((MultipartReply) msg).getType() == MultipartType.OFPMPTABLEFEATURES) {
50 LOG.debug("MultipartReply Being translated to TableUpdated ");
51 MultipartReplyMessage mpReply = (MultipartReplyMessage) msg;
53 List<DataObject> listDataObject = new CopyOnWriteArrayList<>();
55 TableUpdatedBuilder message = new TableUpdatedBuilder();
56 message.setNode((new NodeRef(InventoryDataServiceUtil.identifierFromDatapathId(sc.getFeatures()
58 message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE());
59 message.setTransactionId(new TransactionId(BigInteger.valueOf(mpReply.getXid())));
60 MultipartReplyTableFeaturesCase caseBody = (MultipartReplyTableFeaturesCase) mpReply.getMultipartReplyBody();
61 MultipartReplyTableFeatures body = caseBody.getMultipartReplyTableFeatures();
63 final VersionConvertorData data = new VersionConvertorData(sc.getPrimaryConductor().getVersion());
64 final Optional<List<TableFeatures>> tableFeaturesList = convertorExecutor.convert(body, data);
65 message.setTableFeatures(tableFeaturesList.orElse(Collections.emptyList()));
66 listDataObject.add( message.build()) ;
68 return listDataObject ;
71 return Collections.emptyList();