2 * Copyright (c) 2014 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
8 package org.opendaylight.openflowplugin.openflow.md.core.extension;
10 import static org.junit.Assert.assertNotNull;
11 import static org.mockito.Mockito.when;
13 import java.util.ArrayList;
14 import java.util.List;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Mock;
19 import org.mockito.junit.MockitoJUnitRunner;
20 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
21 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
22 import org.opendaylight.openflowplugin.extension.api.AugmentTuple;
23 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
24 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
25 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
26 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
33 import org.opendaylight.yangtools.yang.binding.Augmentation;
36 * Created by Martin Bobak mbobak@cisco.com on 9/19/14.
38 @RunWith(MockitoJUnitRunner.class)
39 public class MatchExtensionHelperTest {
42 private ExtensionConverterProvider extensionConverterProvider;
43 private static final MatchEntrySerializerKey<?, ?> KEY_1 =
44 new MatchEntrySerializerKey<>(OpenflowVersion.OF13.getVersion(), MockOxmClassBase.VALUE, MockMatchField1.VALUE);
45 private static final MatchEntrySerializerKey<?, ?> KEY_2 =
46 new MatchEntrySerializerKey<>(OpenflowVersion.OF13.getVersion(), MockOxmClassBase.VALUE, MockMatchField2.VALUE);
50 OFSessionUtil.getSessionManager().setExtensionConverterProvider(extensionConverterProvider);
51 when(extensionConverterProvider.getConverter(KEY_1))
52 .thenReturn((input, path) -> {
53 MockAugmentation mockAugmentation = new MockAugmentation();
54 return new ExtensionAugment<>(MockAugmentation.class, mockAugmentation, MockExtensionKey1.VALUE);
56 when(extensionConverterProvider.getConverter(KEY_2))
57 .thenReturn((input, path) -> {
58 MockAugmentation mockAugmentation = new MockAugmentation();
59 return new ExtensionAugment<>(MockAugmentation.class, mockAugmentation, MockExtensionKey2.VALUE);
66 * Basic functionality test method for {@link MatchExtensionHelper#processAllExtensions(Collection,
67 * OpenflowVersion, MatchPath)}.
69 public void testProcessAllExtensions() {
71 List<MatchEntry> matchEntries = createMatchEntrieses();
72 AugmentTuple<?> augmentTuple = MatchExtensionHelper.processAllExtensions(matchEntries, OpenflowVersion.OF13,
73 MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
74 assertNotNull(augmentTuple);
76 augmentTuple = MatchExtensionHelper.processAllExtensions(matchEntries, OpenflowVersion.OF13,
77 MatchPath.PACKET_RECEIVED_MATCH);
78 assertNotNull(augmentTuple);
80 augmentTuple = MatchExtensionHelper.processAllExtensions(matchEntries, OpenflowVersion.OF13,
81 MatchPath.SWITCH_FLOW_REMOVED_MATCH);
82 assertNotNull(augmentTuple);
86 private static List<MatchEntry> createMatchEntrieses() {
87 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
88 matchEntryBuilder.setHasMask(true);
89 matchEntryBuilder.setOxmClass(MockOxmClassBase.VALUE);
90 matchEntryBuilder.setOxmMatchField(MockMatchField1.VALUE);
91 List<MatchEntry> matchEntries = new ArrayList<>();
92 matchEntries.add(matchEntryBuilder.build());
95 MatchEntryBuilder matchEntryBuilder1 = new MatchEntryBuilder();
96 matchEntryBuilder1.setHasMask(true);
97 matchEntryBuilder1.setOxmClass(MockOxmClassBase.VALUE);
98 matchEntryBuilder1.setOxmMatchField(MockMatchField2.VALUE);
99 matchEntries.add(matchEntryBuilder1.build());
103 private interface MockOxmClassBase extends OxmClassBase {
104 MockOxmClassBase VALUE = () -> MockOxmClassBase.class;
107 private interface MockMatchField1 extends MatchField {
108 MockMatchField1 VALUE = () -> MockMatchField1.class;
111 private interface MockMatchField2 extends MatchField {
112 MockMatchField2 VALUE = () -> MockMatchField2.class;
115 private interface MockExtensionKey1 extends ExtensionKey {
116 MockExtensionKey1 VALUE = () -> MockExtensionKey1.class;
119 private interface MockExtensionKey2 extends ExtensionKey {
120 MockExtensionKey2 VALUE = () -> MockExtensionKey2.class;
123 private static final class MockAugmentation implements Augmentation<Extension> {
125 public Class<MockAugmentation> implementedInterface() {
126 return MockAugmentation.class;