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
9 package org.opendaylight.openflowplugin.openflow.md.core.extension;
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.Mockito.when;
14 import java.util.ArrayList;
15 import java.util.List;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.runners.MockitoJUnitRunner;
21 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
22 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
23 import org.opendaylight.openflowplugin.extension.api.AugmentTuple;
24 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
25 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
26 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
27 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
37 * Created by Martin Bobak mbobak@cisco.com on 9/19/14.
39 @RunWith(MockitoJUnitRunner.class)
40 public class MatchExtensionHelperTest {
43 private ExtensionConverterProvider extensionConverterProvider;
44 private static final int PRESET_COUNT = 7;
45 private static final MatchEntrySerializerKey<? extends OxmClassBase, ? extends MatchField> KEY =
46 new MatchEntrySerializerKey<>(OpenflowVersion.OF13.getVersion(), MockOxmClassBase.class, MockMatchField.class);
50 OFSessionUtil.getSessionManager().setExtensionConverterProvider(extensionConverterProvider);
51 when(extensionConverterProvider.getConverter(KEY))
52 .thenReturn((input, path) -> {
53 MockAugmentation mockAugmentation = new MockAugmentation();
54 return new ExtensionAugment<>(MockAugmentation.class, mockAugmentation, MockExtensionKey.class);
61 * Basic functionality test method for {@link MatchExtensionHelper#processAllExtensions(Collection,
62 * OpenflowVersion, MatchPath)}.
64 public void testProcessAllExtensions() {
66 List<MatchEntry> matchEntries = createMatchEntrieses();
67 AugmentTuple augmentTuple = MatchExtensionHelper.processAllExtensions(matchEntries, OpenflowVersion.OF13,
68 MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
69 assertNotNull(augmentTuple);
71 augmentTuple = MatchExtensionHelper.processAllExtensions(matchEntries, OpenflowVersion.OF13,
72 MatchPath.PACKET_RECEIVED_MATCH);
73 assertNotNull(augmentTuple);
75 augmentTuple = MatchExtensionHelper.processAllExtensions(matchEntries, OpenflowVersion.OF13,
76 MatchPath.SWITCH_FLOW_REMOVED_MATCH);
77 assertNotNull(augmentTuple);
81 private static List<MatchEntry> createMatchEntrieses() {
82 List<MatchEntry> matchEntries = new ArrayList<>();
83 for (int i = 0; i < PRESET_COUNT; i++) {
84 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
85 matchEntryBuilder.setHasMask(true);
86 matchEntryBuilder.setOxmClass(MockOxmClassBase.class);
87 matchEntryBuilder.setOxmMatchField(MockMatchField.class);
88 matchEntries.add(matchEntryBuilder.build());
93 private interface MockOxmClassBase extends OxmClassBase {
97 private interface MockMatchField extends MatchField {
101 private interface MockExtensionKey extends ExtensionKey {
105 private final class MockAugmentation implements Augmentation<Extension> {