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
9 package org.opendaylight.openflowplugin.extension.vendor.eric.convertor.match;
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Mockito.when;
14 import java.util.Collections;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Matchers;
20 import org.mockito.Mock;
21 import org.mockito.junit.MockitoJUnitRunner;
22 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
23 import org.opendaylight.openflowplugin.extension.api.GroupingLooseResolver;
24 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
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.openflowjava.eric.match.rev180730.icmpv6.nd.reserved.grouping.Icmpv6NdReservedValuesBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.oxm.container.match.entry.value.Icmpv6NdReservedCaseValue;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.oxm.container.match.entry.value.Icmpv6NdReservedCaseValueBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNodesNodeTableFlow;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNodesNodeTableFlowBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifPacketIn;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifSwitchFlowRemoved;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchRpcGetFlowStats;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.Icmpv6NdReservedKey;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.eric.of.icmpv6.nd.reserved.grouping.EricOfIcmpv6NdReservedBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowWriteActionsSetField;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionListGrouping;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
44 import org.opendaylight.yangtools.yang.binding.Augmentation;
48 * Test for {@link Icmpv6NDReservedConvertor}.
50 @RunWith(MockitoJUnitRunner.class)
51 public class Icmpv6NDReservedConvertorTest {
54 private Extension extension;
56 private MatchEntry matchEntry;
58 private Icmpv6NDReservedConvertor icmpv6NDReservedConvertor;
62 final EricOfIcmpv6NdReservedBuilder ericOfIcmpv6NdReservedBuilder = new EricOfIcmpv6NdReservedBuilder()
63 .setIcmpv6NdReserved(1L);
64 final EricAugMatchNodesNodeTableFlowBuilder ericAugMatchNotifUpdateFlowStatsBuilder =
65 new EricAugMatchNodesNodeTableFlowBuilder();
66 ericAugMatchNotifUpdateFlowStatsBuilder.setEricOfIcmpv6NdReserved(ericOfIcmpv6NdReservedBuilder.build());
68 final Augmentation<Extension> extensionAugmentation = ericAugMatchNotifUpdateFlowStatsBuilder.build();
69 when(extension.augmentation(Matchers.any()))
70 .thenReturn(extensionAugmentation);
72 icmpv6NDReservedConvertor = new Icmpv6NDReservedConvertor();
76 public void testConvert() {
77 final MatchEntry converted = icmpv6NDReservedConvertor.convert(extension);
78 assertEquals(1, ((Icmpv6NdReservedCaseValue)converted.getMatchEntryValue())
79 .getIcmpv6NdReservedValues().getIcmpv6NdReserved().intValue());
83 public void testConvert1() {
84 final Icmpv6NdReservedValuesBuilder icmpv6NdReservedValuesBuilder = new Icmpv6NdReservedValuesBuilder()
85 .setIcmpv6NdReserved(10L);
86 final Icmpv6NdReservedCaseValueBuilder icmpv6NdReservedCaseValueBuilder = new Icmpv6NdReservedCaseValueBuilder()
87 .setIcmpv6NdReservedValues(icmpv6NdReservedValuesBuilder.build());
89 final Icmpv6NdReservedCaseValue icmpv6NdReservedCaseValue = icmpv6NdReservedCaseValueBuilder.build();
90 when(matchEntry.getMatchEntryValue()).thenReturn(icmpv6NdReservedCaseValue);
92 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment
93 = icmpv6NDReservedConvertor.convert(matchEntry, MatchPath.PACKET_RECEIVED_MATCH);
94 assertEquals(10, ((EricAugMatchNotifPacketIn) extensionAugment.getAugmentationObject())
95 .getEricOfIcmpv6NdReserved().getIcmpv6NdReserved().intValue());
96 assertEquals(extensionAugment.getKey(), Icmpv6NdReservedKey.class);
98 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1
99 = icmpv6NDReservedConvertor.convert(matchEntry, MatchPath.SWITCH_FLOW_REMOVED_MATCH);
100 assertEquals(10, ((EricAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
101 .getEricOfIcmpv6NdReserved().getIcmpv6NdReserved().intValue());
102 assertEquals(extensionAugment.getKey(), Icmpv6NdReservedKey.class);
104 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2
105 = icmpv6NDReservedConvertor.convert(matchEntry, MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
106 assertEquals(10, ((EricAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
107 .getEricOfIcmpv6NdReserved().getIcmpv6NdReserved().intValue());
108 assertEquals(extensionAugment.getKey(), Icmpv6NdReservedKey.class);
110 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3
111 = icmpv6NDReservedConvertor.convert(matchEntry, MatchPath.FLOWS_STATISTICS_RPC_MATCH);
112 assertEquals(10, ((EricAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject())
113 .getEricOfIcmpv6NdReserved().getIcmpv6NdReserved().intValue());
114 assertEquals(extensionAugment.getKey(), Icmpv6NdReservedKey.class);
118 public void testSetFieldExtension() {
119 GroupingLooseResolver<GeneralExtensionListGrouping> eqGroup =
120 new GroupingLooseResolver<>(GeneralExtensionListGrouping.class);
121 eqGroup.add(GeneralAugMatchNodesNodeTableFlowWriteActionsSetField.class);
123 ExtensionAugment<? extends Augmentation<Extension>> extensionMatch
124 = new ExtensionAugment<>(EricAugMatchNodesNodeTableFlow.class,
125 new EricAugMatchNodesNodeTableFlowBuilder().setEricOfIcmpv6NdReserved(
126 new EricOfIcmpv6NdReservedBuilder().setIcmpv6NdReserved(1L).build()).build(),
127 Icmpv6NdReservedKey.class);
129 ExtensionListBuilder extListBld = null;
130 ExtensionBuilder extBld = new ExtensionBuilder();
131 extBld.addAugmentation(extensionMatch.getAugmentationClass(), extensionMatch.getAugmentationObject());
133 extListBld = new ExtensionListBuilder();
134 extListBld.setExtension(extBld.build());
135 extListBld.setExtensionKey(extensionMatch.getKey());
137 GeneralAugMatchNodesNodeTableFlowWriteActionsSetField ndReservedSetField =
138 new GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder()
139 .setExtensionList(Collections.singletonList(extListBld.build())).build();
141 SetFieldBuilder sb = new SetFieldBuilder();
142 SetField setField = sb.addAugmentation(GeneralAugMatchNodesNodeTableFlowWriteActionsSetField.class,
143 ndReservedSetField).build();
145 Assert.assertEquals(Icmpv6NdReservedKey.class, eqGroup.getExtension(setField).get().getExtensionList().get(0)