Claudine Chiu | 1f036b8 | 2017-03-09 16:45:56 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Claudine Chiu | 1f036b8 | 2017-03-09 16:45:56 -0500 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package org.onosproject.incubator.net.virtual.impl; |
| 18 | |
| 19 | import org.junit.After; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Ignore; |
| 22 | import org.junit.Test; |
| 23 | import org.onlab.junit.TestUtils; |
| 24 | import org.onlab.osgi.ComponentContextAdapter; |
| 25 | import org.onosproject.cfg.ComponentConfigAdapter; |
| 26 | import org.onosproject.cluster.ClusterService; |
| 27 | import org.onosproject.cluster.ClusterServiceAdapter; |
| 28 | import org.onosproject.cluster.NodeId; |
| 29 | import org.onosproject.incubator.store.virtual.impl.DistributedVirtualPacketStore; |
| 30 | import org.onosproject.mastership.MastershipServiceAdapter; |
| 31 | import org.onosproject.net.DeviceId; |
| 32 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 33 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 34 | import org.onosproject.net.packet.OutboundPacket; |
| 35 | import org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter; |
| 36 | import org.onosproject.store.cluster.messaging.MessageSubject; |
| 37 | |
| 38 | import java.nio.ByteBuffer; |
| 39 | import java.util.concurrent.CompletableFuture; |
| 40 | import java.util.function.Function; |
| 41 | |
| 42 | import 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 | */ |
| 49 | public 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 | } |