2 * Copyright (c) 2019 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 package org.opendaylight.openflowplugin.extension.vendor.eric.convertor.match;
10 import java.util.Optional;
11 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
12 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
13 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
14 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
15 import org.opendaylight.openflowplugin.extension.vendor.eric.convertor.CodecPreconditionException;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EricExpClass;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.Icmpv6NdReserved;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.icmpv6.nd.reserved.grouping.Icmpv6NdReservedValuesBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.ofj.aug.eric.match.reserved.Icmpv6NdReservedCaseValue;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.ofj.aug.eric.match.reserved.Icmpv6NdReservedCaseValueBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNodesNodeTableFlow;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNodesNodeTableFlowBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifPacketIn;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifPacketInBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifSwitchFlowRemoved;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifSwitchFlowRemovedBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchPacketInMessage;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchPacketInMessageBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchRpcGetFlowStats;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchRpcGetFlowStatsBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricOfIcmpv6NdReservedGrouping;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.Icmpv6NdReservedKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.eric.of.icmpv6.nd.reserved.grouping.EricOfIcmpv6NdReserved;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.eric.of.icmpv6.nd.reserved.grouping.EricOfIcmpv6NdReservedBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
38 import org.opendaylight.yangtools.yang.binding.Augmentation;
39 import org.opendaylight.yangtools.yang.common.Uint32;
42 * Convert to/from SAL flow model to openflowjava model for Icmpv6NDReservedCase.
44 public class Icmpv6NDReservedConvertor implements ConvertorToOFJava<MatchEntry>,
45 ConvertorFromOFJava<MatchEntry, MatchPath> {
48 public ExtensionAugment<? extends Augmentation<Extension>> convert(final MatchEntry input, final MatchPath path) {
49 Icmpv6NdReservedCaseValue icmpv6NdReservedCaseValue = (Icmpv6NdReservedCaseValue) input.getMatchEntryValue();
50 return resolveAugmentation(new EricOfIcmpv6NdReservedBuilder().setIcmpv6NdReserved(
51 icmpv6NdReservedCaseValue.getIcmpv6NdReservedValues().getIcmpv6NdReserved()).build(), path,
52 Icmpv6NdReservedKey.class);
56 public MatchEntry convert(final Extension extension) {
57 Optional<EricOfIcmpv6NdReservedGrouping> matchGrouping
58 = MatchUtil.ICMPV6_ND_RESERVED_RESOLVER.getExtension(extension);
59 if (!matchGrouping.isPresent()) {
60 throw new CodecPreconditionException(extension);
62 Uint32 value = matchGrouping.get().getEricOfIcmpv6NdReserved().getIcmpv6NdReserved();
63 Icmpv6NdReservedCaseValueBuilder icmpv6NdReservedCaseValueBuilder = new Icmpv6NdReservedCaseValueBuilder();
64 icmpv6NdReservedCaseValueBuilder.setIcmpv6NdReservedValues(new Icmpv6NdReservedValuesBuilder()
65 .setIcmpv6NdReserved(value).build());
66 return MatchUtil.createDefaultMatchEntryBuilder(Icmpv6NdReserved.class, EricExpClass.class,
67 icmpv6NdReservedCaseValueBuilder.build()).build();
70 private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(
71 final EricOfIcmpv6NdReserved value, final MatchPath path, final Class<? extends ExtensionKey> key) {
73 case FLOWS_STATISTICS_UPDATE_MATCH:
74 return new ExtensionAugment<>(EricAugMatchNodesNodeTableFlow.class,
75 new EricAugMatchNodesNodeTableFlowBuilder().setEricOfIcmpv6NdReserved(value).build(), key);
76 case FLOWS_STATISTICS_RPC_MATCH:
77 return new ExtensionAugment<>(EricAugMatchRpcGetFlowStats.class,
78 new EricAugMatchRpcGetFlowStatsBuilder().setEricOfIcmpv6NdReserved(value).build(), key);
79 case PACKET_RECEIVED_MATCH:
80 return new ExtensionAugment<>(EricAugMatchNotifPacketIn.class, new EricAugMatchNotifPacketInBuilder()
81 .setEricOfIcmpv6NdReserved(value).build(), key);
82 case SWITCH_FLOW_REMOVED_MATCH:
83 return new ExtensionAugment<>(EricAugMatchNotifSwitchFlowRemoved.class,
84 new EricAugMatchNotifSwitchFlowRemovedBuilder().setEricOfIcmpv6NdReserved(value).build(), key);
85 case PACKET_IN_MESSAGE_MATCH:
86 return new ExtensionAugment<>(EricAugMatchPacketInMessage.class,
87 new EricAugMatchPacketInMessageBuilder().setEricOfIcmpv6NdReserved(value).build(), key);
89 throw new CodecPreconditionException(path);