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;
14 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
15 import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
16 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
17 import org.opendaylight.openflowplugin.extension.api.AugmentTuple;
18 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
19 import org.opendaylight.openflowplugin.impl.util.NodeConnectorRefToPortTranslator;
20 import org.opendaylight.openflowplugin.openflow.md.core.extension.MatchExtensionHelper;
21 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
22 import org.opendaylight.openflowplugin.openflow.md.util.PacketInUtil;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.MatchBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId;
33 * Created by tkubas on 4/1/15.
35 public class PacketReceivedTranslator implements MessageTranslator<PacketInMessage, PacketReceived> {
37 public PacketReceived translate(final PacketInMessage input, final DeviceInfo deviceInfo, final Object connectionDistinguisher) {
39 PacketReceivedBuilder packetReceivedBuilder = new PacketReceivedBuilder();
40 BigInteger datapathId = deviceInfo.getDatapathId();
42 // TODO: connection cookie from connection distinguisher
43 // packetReceivedBuilder.setConnectionCookie(new ConnectionCookie(input.getCookie().longValue()));
45 packetReceivedBuilder.setPayload(input.getData());
47 // get the Cookie if it exists
48 if (input.getCookie() != null) {
49 packetReceivedBuilder.setFlowCookie(new FlowCookie(input.getCookie()));
52 // Try to create the NodeConnectorRef
53 BigInteger dataPathId = deviceInfo.getDatapathId();
54 NodeConnectorRef nodeConnectorRef = NodeConnectorRefToPortTranslator.toNodeConnectorRef(input, dataPathId);
56 // If we was able to create NodeConnectorRef, use it
57 if (nodeConnectorRef != null) {
58 packetReceivedBuilder.setIngress(nodeConnectorRef);
61 packetReceivedBuilder.setPacketInReason(PacketInUtil.getMdSalPacketInReason(input.getReason()));
63 if (input.getTableId() != null) {
64 packetReceivedBuilder.setTableId(new TableId(input.getTableId().getValue().shortValue()));
67 if (input.getMatch() != null) {
68 org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match packetInMatch = getPacketInMatch(input, datapathId);
69 packetReceivedBuilder.setMatch(packetInMatch);
72 return packetReceivedBuilder.build();
76 static org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match getPacketInMatch(final PacketInMessage input, final BigInteger datapathId) {
77 Match match = MatchConvertorImpl.fromOFMatchToSALMatch(input.getMatch(),
79 OpenflowVersion.get(input.getVersion().shortValue())).build();
80 MatchBuilder matchBuilder = new MatchBuilder(match);
82 AugmentTuple<org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match> matchExtensionWrap =
83 MatchExtensionHelper.processAllExtensions(
84 input.getMatch().getMatchEntry(), OpenflowVersion.get(input.getVersion().shortValue()), MatchPath.PACKETRECEIVED_MATCH);
85 if (matchExtensionWrap != null) {
86 matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationClass(), matchExtensionWrap.getAugmentationObject());
88 return matchBuilder.build();