blob: e21808800c3bc07ed54857d6e282ac7468420764 [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;
Marcos Aurelio Carreroeaf02b82019-11-25 13:34:25 -030022import org.onlab.junit.TestUtils;
23import org.onlab.osgi.ComponentContextAdapter;
24import org.onosproject.cfg.ComponentConfigService;
Jonathan Hart617bc3e2020-02-14 10:42:23 -080025import org.onosproject.cluster.LeadershipServiceAdapter;
Marcos Aurelio Carreroeaf02b82019-11-25 13:34:25 -030026import org.onosproject.net.ConnectPoint;
27import org.onosproject.net.config.Config;
28import org.onosproject.net.config.NetworkConfigRegistryAdapter;
29import org.onosproject.net.flowobjective.FlowObjectiveServiceAdapter;
Jonathan Hart617bc3e2020-02-14 10:42:23 -080030import org.onosproject.store.service.TestStorageService;
Marcos Aurelio Carreroeaf02b82019-11-25 13:34:25 -030031
32import java.util.Set;
33
Jonathan Hart617bc3e2020-02-14 10:42:23 -080034import static org.hamcrest.Matchers.is;
35import static org.junit.Assert.assertNull;
36import static org.junit.Assert.assertThat;
37import static org.junit.Assert.assertTrue;
38
Marcos Aurelio Carreroeaf02b82019-11-25 13:34:25 -030039/**
40 * Tests for DHCP relay app configuration.
41 */
42public class DhcpL2RelayConfigTest extends DhcpL2RelayTestBase {
43
44 static final boolean USE_OLT_ULPORT_FOR_PKT_INOUT = true;
45 static final boolean MODIFY_SRC_DST_MAC = true;
46
47 private DhcpL2Relay dhcpL2Relay;
48
49 ComponentConfigService mockConfigService =
50 EasyMock.createMock(ComponentConfigService.class);
51
52 /**
53 * Sets up the services required by the dhcpl2relay app.
54 */
55 @Before
56 public void setUp() {
57 dhcpL2Relay = new DhcpL2Relay();
58 dhcpL2Relay.cfgService = new TestNetworkConfigRegistry();
59 dhcpL2Relay.coreService = new MockCoreServiceAdapter();
60 dhcpL2Relay.flowObjectiveService = new FlowObjectiveServiceAdapter();
61 dhcpL2Relay.packetService = new MockPacketService();
62 dhcpL2Relay.componentConfigService = mockConfigService;
63 dhcpL2Relay.deviceService = new MockDeviceService();
64 dhcpL2Relay.sadisService = new MockSadisService();
65 dhcpL2Relay.hostService = new MockHostService();
66 dhcpL2Relay.mastershipService = new MockMastershipService();
Jonathan Hart617bc3e2020-02-14 10:42:23 -080067 dhcpL2Relay.storageService = new TestStorageService();
68 dhcpL2Relay.leadershipService = new LeadershipServiceAdapter();
Jonathan Hart77ca3152020-02-21 14:31:21 -080069 SimpleDhcpL2RelayCountersStore store = new SimpleDhcpL2RelayCountersStore();
70 store.componentConfigService = mockConfigService;
71 dhcpL2Relay.dhcpL2RelayCounters = store;
Marcos Aurelio Carreroeaf02b82019-11-25 13:34:25 -030072 TestUtils.setField(dhcpL2Relay, "eventDispatcher", new TestEventDispatcher());
73 dhcpL2Relay.activate(new ComponentContextAdapter());
74 }
75
76 /**
77 * Mocks the network config registry.
78 */
79 static class MockDhcpL2RelayConfig extends DhcpL2RelayConfig {
80 @Override
81 public Set<ConnectPoint> getDhcpServerConnectPoint() {
82 return ImmutableSet.of(SERVER_CONNECT_POINT);
83 }
84
85 @Override
86 public boolean getModifySrcDstMacAddresses() {
87 return true;
88 }
89
90 @Override
91 public boolean getUseOltUplinkForServerPktInOut() {
92 return true;
93 }
94 }
95
96 /**
97 * Tests the default configuration.
98 */
99 @Test
100 public void testConfig() {
101 assertThat(dhcpL2Relay.useOltUplink, is(USE_OLT_ULPORT_FOR_PKT_INOUT));
102 assertThat(dhcpL2Relay.modifyClientPktsSrcDstMac, is(MODIFY_SRC_DST_MAC));
103 assertNull(dhcpL2Relay.dhcpServerConnectPoint.get());
104 }
105
106 /**
107 * Tests if dhcpl2relay app has been configured.
108 */
109 @Test
110 public void testDhcpL2RelayConfigured() {
111 assertTrue(dhcpL2Relay.configured());
112 }
113
114 /**
115 * Mocks the network config registry.
116 */
117 @SuppressWarnings("unchecked")
118 static final class TestNetworkConfigRegistry
119 extends NetworkConfigRegistryAdapter {
120 @Override
121 public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
122 DhcpL2RelayConfig dhcpConfig = new MockDhcpL2RelayConfig();
123 return (C) dhcpConfig;
124 }
125 }
126}