e1418e16ca9d792646dc64cea403ecad06230f96
[openflowplugin.git] / extension / openflowplugin-extension-eric / src / main / java / org / opendaylight / openflowplugin / extension / vendor / eric / convertor / match / Icmpv6NDReservedConvertor.java
1 /*
2  * Copyright (c) 2019 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.extension.vendor.eric.convertor.match;
10
11 import com.google.common.base.Optional;
12 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
13 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
14 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
15 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
16 import org.opendaylight.openflowplugin.extension.vendor.eric.convertor.CodecPreconditionException;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EricExpClass;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.Icmpv6NdReserved;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.icmpv6.nd.reserved.grouping.Icmpv6NdReservedValuesBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.oxm.container.match.entry.value.Icmpv6NdReservedCaseValue;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.oxm.container.match.entry.value.Icmpv6NdReservedCaseValueBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNodesNodeTableFlow;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNodesNodeTableFlowBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifPacketIn;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifPacketInBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifSwitchFlowRemoved;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifSwitchFlowRemovedBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchPacketInMessage;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchPacketInMessageBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchRpcGetFlowStats;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchRpcGetFlowStatsBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricOfIcmpv6NdReservedGrouping;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.Icmpv6NdReservedKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.eric.of.icmpv6.nd.reserved.grouping.EricOfIcmpv6NdReserved;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.eric.of.icmpv6.nd.reserved.grouping.EricOfIcmpv6NdReservedBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
39 import org.opendaylight.yangtools.yang.binding.Augmentation;
40 import org.opendaylight.yangtools.yang.common.Uint32;
41
42 /**
43  * Convert to/from SAL flow model to openflowjava model for Icmpv6NDReservedCase.
44  */
45 public class Icmpv6NDReservedConvertor implements ConvertorToOFJava<MatchEntry>,
46         ConvertorFromOFJava<MatchEntry, MatchPath> {
47
48     @Override
49     public ExtensionAugment<? extends Augmentation<Extension>> convert(MatchEntry input, MatchPath path) {
50         Icmpv6NdReservedCaseValue icmpv6NdReservedCaseValue = (Icmpv6NdReservedCaseValue) input.getMatchEntryValue();
51         return resolveAugmentation(new EricOfIcmpv6NdReservedBuilder().setIcmpv6NdReserved(
52                 icmpv6NdReservedCaseValue.getIcmpv6NdReservedValues().getIcmpv6NdReserved()).build(), path,
53                 Icmpv6NdReservedKey.class);
54     }
55
56     @Override
57     public MatchEntry convert(Extension extension) {
58         Optional<EricOfIcmpv6NdReservedGrouping> matchGrouping
59                 = MatchUtil.ICMPV6_ND_RESERVED_RESOLVER.getExtension(extension);
60         if (!matchGrouping.isPresent()) {
61             throw new CodecPreconditionException(extension);
62         }
63         Uint32 value = matchGrouping.get().getEricOfIcmpv6NdReserved().getIcmpv6NdReserved();
64         Icmpv6NdReservedCaseValueBuilder icmpv6NdReservedCaseValueBuilder = new Icmpv6NdReservedCaseValueBuilder();
65         icmpv6NdReservedCaseValueBuilder.setIcmpv6NdReservedValues(new Icmpv6NdReservedValuesBuilder()
66                 .setIcmpv6NdReserved(value).build());
67         return MatchUtil.createDefaultMatchEntryBuilder(Icmpv6NdReserved.class, EricExpClass.class,
68                 icmpv6NdReservedCaseValueBuilder.build()).build();
69     }
70
71     private static ExtensionAugment<? extends Augmentation<Extension>> resolveAugmentation(EricOfIcmpv6NdReserved value,
72             MatchPath path, Class<? extends ExtensionKey> key) {
73         switch (path) {
74             case FLOWS_STATISTICS_UPDATE_MATCH:
75                 return new ExtensionAugment<>(EricAugMatchNodesNodeTableFlow.class,
76                         new EricAugMatchNodesNodeTableFlowBuilder().setEricOfIcmpv6NdReserved(value).build(), key);
77             case FLOWS_STATISTICS_RPC_MATCH:
78                 return new ExtensionAugment<>(EricAugMatchRpcGetFlowStats.class,
79                         new EricAugMatchRpcGetFlowStatsBuilder().setEricOfIcmpv6NdReserved(value).build(), key);
80             case PACKET_RECEIVED_MATCH:
81                 return new ExtensionAugment<>(EricAugMatchNotifPacketIn.class, new EricAugMatchNotifPacketInBuilder()
82                         .setEricOfIcmpv6NdReserved(value).build(), key);
83             case SWITCH_FLOW_REMOVED_MATCH:
84                 return new ExtensionAugment<>(EricAugMatchNotifSwitchFlowRemoved.class,
85                         new EricAugMatchNotifSwitchFlowRemovedBuilder().setEricOfIcmpv6NdReserved(value).build(), key);
86             case PACKET_IN_MESSAGE_MATCH:
87                 return new ExtensionAugment<>(EricAugMatchPacketInMessage.class,
88                         new EricAugMatchPacketInMessageBuilder().setEricOfIcmpv6NdReserved(value).build(), key);
89             default:
90                 throw new CodecPreconditionException(path);
91         }
92     }
93
94 }