blob: 94a90c873ec5a6b97508630c411cd1b4db658895 [file] [log] [blame]
Marcos Aurelio Carreroeaf02b82019-11-25 13:34:25 -03001/*
2 * Copyright 2017-present Open Networking Foundation
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 */
16package org.opencord.dhcpl2relay.impl;
17
18import com.google.common.collect.ImmutableSet;
19import org.easymock.EasyMock;
20import org.junit.Before;
21import org.junit.Test;
22
23import static org.hamcrest.Matchers.is;
24import static org.junit.Assert.*;
25
26import org.onlab.junit.TestUtils;
27import org.onlab.osgi.ComponentContextAdapter;
28import org.onosproject.cfg.ComponentConfigService;
29import org.onosproject.common.event.impl.TestEventDispatcher;
30import org.onosproject.net.ConnectPoint;
31import org.onosproject.net.config.Config;
32import org.onosproject.net.config.NetworkConfigRegistryAdapter;
33import org.onosproject.net.flowobjective.FlowObjectiveServiceAdapter;
34
35import java.util.Set;
36
37/**
38 * Tests for DHCP relay app configuration.
39 */
40public class DhcpL2RelayConfigTest extends DhcpL2RelayTestBase {
41
42 static final boolean USE_OLT_ULPORT_FOR_PKT_INOUT = true;
43 static final boolean MODIFY_SRC_DST_MAC = true;
44
45 private DhcpL2Relay dhcpL2Relay;
46
47 ComponentConfigService mockConfigService =
48 EasyMock.createMock(ComponentConfigService.class);
49
50 /**
51 * Sets up the services required by the dhcpl2relay app.
52 */
53 @Before
54 public void setUp() {
55 dhcpL2Relay = new DhcpL2Relay();
56 dhcpL2Relay.cfgService = new TestNetworkConfigRegistry();
57 dhcpL2Relay.coreService = new MockCoreServiceAdapter();
58 dhcpL2Relay.flowObjectiveService = new FlowObjectiveServiceAdapter();
59 dhcpL2Relay.packetService = new MockPacketService();
60 dhcpL2Relay.componentConfigService = mockConfigService;
61 dhcpL2Relay.deviceService = new MockDeviceService();
62 dhcpL2Relay.sadisService = new MockSadisService();
63 dhcpL2Relay.hostService = new MockHostService();
64 dhcpL2Relay.mastershipService = new MockMastershipService();
65 TestUtils.setField(dhcpL2Relay, "eventDispatcher", new TestEventDispatcher());
66 dhcpL2Relay.activate(new ComponentContextAdapter());
67 }
68
69 /**
70 * Mocks the network config registry.
71 */
72 static class MockDhcpL2RelayConfig extends DhcpL2RelayConfig {
73 @Override
74 public Set<ConnectPoint> getDhcpServerConnectPoint() {
75 return ImmutableSet.of(SERVER_CONNECT_POINT);
76 }
77
78 @Override
79 public boolean getModifySrcDstMacAddresses() {
80 return true;
81 }
82
83 @Override
84 public boolean getUseOltUplinkForServerPktInOut() {
85 return true;
86 }
87 }
88
89 /**
90 * Tests the default configuration.
91 */
92 @Test
93 public void testConfig() {
94 assertThat(dhcpL2Relay.useOltUplink, is(USE_OLT_ULPORT_FOR_PKT_INOUT));
95 assertThat(dhcpL2Relay.modifyClientPktsSrcDstMac, is(MODIFY_SRC_DST_MAC));
96 assertNull(dhcpL2Relay.dhcpServerConnectPoint.get());
97 }
98
99 /**
100 * Tests if dhcpl2relay app has been configured.
101 */
102 @Test
103 public void testDhcpL2RelayConfigured() {
104 assertTrue(dhcpL2Relay.configured());
105 }
106
107 /**
108 * Mocks the network config registry.
109 */
110 @SuppressWarnings("unchecked")
111 static final class TestNetworkConfigRegistry
112 extends NetworkConfigRegistryAdapter {
113 @Override
114 public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
115 DhcpL2RelayConfig dhcpConfig = new MockDhcpL2RelayConfig();
116 return (C) dhcpConfig;
117 }
118 }
119}