2 * Copyright (c) 2015 Cisco Systems, Inc. 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.impl.translator;
11 import com.google.common.annotations.VisibleForTesting;
12 import java.math.BigInteger;
13 import java.util.List;
14 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
15 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
16 import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
17 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
18 import org.opendaylight.openflowplugin.extension.api.AugmentTuple;
19 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
20 import org.opendaylight.openflowplugin.impl.util.NodeConnectorRefToPortTranslator;
21 import org.opendaylight.openflowplugin.openflow.md.core.extension.MatchExtensionHelper;
22 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
23 import org.opendaylight.openflowplugin.openflow.md.util.PacketInUtil;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPortCase;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.MatchBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId;
36 * Created by tkubas on 4/1/15.
38 public class PacketReceivedTranslator implements MessageTranslator<PacketInMessage, PacketReceived> {
40 public PacketReceived translate(final PacketInMessage input, final DeviceState deviceState, final Object connectionDistinguisher) {
42 PacketReceivedBuilder packetReceivedBuilder = new PacketReceivedBuilder();
43 BigInteger datapathId = deviceState.getFeatures().getDatapathId();
45 // TODO: connection cookie from connection distinguisher
46 // packetReceivedBuilder.setConnectionCookie(new ConnectionCookie(input.getCookie().longValue()));
48 packetReceivedBuilder.setPayload(input.getData());
50 // get the Cookie if it exists
51 if (input.getCookie() != null) {
52 packetReceivedBuilder.setFlowCookie(new FlowCookie(input.getCookie()));
55 // Try to create the NodeConnectorRef
56 BigInteger dataPathId = deviceState.getFeatures().getDatapathId();
57 NodeConnectorRef nodeConnectorRef = NodeConnectorRefToPortTranslator.toNodeConnectorRef(input, dataPathId);
59 // If we was able to create NodeConnectorRef, use it
60 if (nodeConnectorRef != null) {
61 packetReceivedBuilder.setIngress(nodeConnectorRef);
64 packetReceivedBuilder.setPacketInReason(PacketInUtil.getMdSalPacketInReason(input.getReason()));
66 if (input.getTableId() != null) {
67 packetReceivedBuilder.setTableId(new TableId(input.getTableId().getValue().shortValue()));
70 if (input.getMatch() != null) {
71 org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match packetInMatch = getPacketInMatch(input, datapathId);
72 packetReceivedBuilder.setMatch(packetInMatch);
75 return packetReceivedBuilder.build();
79 static org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match getPacketInMatch(final PacketInMessage input, final BigInteger datapathId) {
80 Match match = MatchConvertorImpl.fromOFMatchToSALMatch(input.getMatch(),
82 OpenflowVersion.get(input.getVersion().shortValue())).build();
83 MatchBuilder matchBuilder = new MatchBuilder(match);
85 AugmentTuple<org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match> matchExtensionWrap =
86 MatchExtensionHelper.processAllExtensions(
87 input.getMatch().getMatchEntry(), OpenflowVersion.get(input.getVersion().shortValue()), MatchPath.PACKETRECEIVED_MATCH);
88 if (matchExtensionWrap != null) {
89 matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationClass(), matchExtensionWrap.getAugmentationObject());
91 return matchBuilder.build();