blob: fd1b7510d36c36d23b7aa2bbc94140641fb40b38 [file] [log] [blame]
Claudine Chiu1f036b82017-03-09 16:45:56 -05001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Claudine Chiu1f036b82017-03-09 16:45:56 -05003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.incubator.net.virtual.impl;
18
19import org.junit.After;
20import org.junit.Before;
21import org.junit.Ignore;
22import org.junit.Test;
23import org.onlab.junit.TestUtils;
24import org.onlab.osgi.ComponentContextAdapter;
25import org.onosproject.cfg.ComponentConfigAdapter;
26import org.onosproject.cluster.ClusterService;
27import org.onosproject.cluster.ClusterServiceAdapter;
28import org.onosproject.cluster.NodeId;
29import org.onosproject.incubator.store.virtual.impl.DistributedVirtualPacketStore;
30import org.onosproject.mastership.MastershipServiceAdapter;
31import org.onosproject.net.DeviceId;
32import org.onosproject.net.flow.DefaultTrafficTreatment;
33import org.onosproject.net.packet.DefaultOutboundPacket;
34import org.onosproject.net.packet.OutboundPacket;
35import org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter;
36import org.onosproject.store.cluster.messaging.MessageSubject;
37
38import java.nio.ByteBuffer;
39import java.util.concurrent.CompletableFuture;
40import java.util.function.Function;
41
42import static org.junit.Assert.assertNull;
43
44/**
45 * Junit tests for VirtualNetworkPacketManager using DistributedVirtualPacketStore..
46 * This test class extends VirtualNetworkPacketManagerTest - all the tests defined in
47 * VirtualNetworkPacketManagerTest will run using DistributedVirtualPacketStore.
48 */
49public class VirtualNetworkPacketManagerWithDistStoreTest extends VirtualNetworkPacketManagerTest {
50
51 private DistributedVirtualPacketStore distStore;
52 private ClusterService clusterService = new ClusterServiceAdapter();
53
54 @Before
55 public void setUp() throws TestUtils.TestUtilsException {
56 setUpDistPacketStore();
57 super.setUp();
58 TestUtils.setField(packetManager1, "storageService", storageService);
59 }
60
61 private void setUpDistPacketStore() throws TestUtils.TestUtilsException {
62 distStore = new DistributedVirtualPacketStore();
63 TestUtils.setField(distStore, "cfgService", new ComponentConfigAdapter());
64 TestUtils.setField(distStore, "storageService", storageService);
65 TestUtils.setField(distStore, "clusterService", clusterService);
66 TestUtils.setField(distStore, "communicationService", new TestClusterCommunicationService());
67 TestUtils.setField(distStore, "mastershipService", new TestMastershipService());
68
69 distStore.activate(new ComponentContextAdapter());
70 packetStore = distStore; // super.setUp() will cause Distributed store to be used.
71 }
72
73 @After
74 public void tearDown() {
75 distStore.deactivate();
76 }
77
78 @Override
79 @Test
80 @Ignore("Ignore until there is MastershipService support for virtual devices")
81 public void emitTest() {
82 super.emitTest();
83 }
84
85 /**
86 * Tests the correct usage of emit() for a outbound packet - master of packet's
87 * sendThrough is not local node.
88 */
89 @Test
90 @Ignore("Ignore until there is MastershipService support for virtual devices")
91 public void emit2Test() {
92 OutboundPacket packet =
93 new DefaultOutboundPacket(VDID2, DefaultTrafficTreatment.emptyTreatment(), ByteBuffer.allocate(5));
94 packetManager1.emit(packet);
95 assertNull("Packet should not have been emmitted", emittedPacket);
96 }
97
98 private final class TestMastershipService extends MastershipServiceAdapter {
99 @Override
100 public NodeId getMasterFor(DeviceId deviceId) {
101 if (VDID1.equals(deviceId)) {
102 return clusterService.getLocalNode().id();
103 }
104 return new NodeId("abc");
105 }
106 }
107
108 private final class TestClusterCommunicationService extends ClusterCommunicationServiceAdapter {
109 @Override
110 public <M> CompletableFuture<Void> unicast(M message, MessageSubject subject,
111 Function<M, byte[]> encoder, NodeId toNodeId) {
112 return new CompletableFuture<>();
113 }
114 }
115
116}