blob: d4cb8bdf0ccc65f584bc522e7829afaec5abbe57 [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();
Marcos Aurelio Carreroeaf02b82019-11-25 13:34:25 -030069 TestUtils.setField(dhcpL2Relay, "eventDispatcher", new TestEventDispatcher());
70 dhcpL2Relay.activate(new ComponentContextAdapter());
71 }
72
73 /**
74 * Mocks the network config registry.
75 */
76 static class MockDhcpL2RelayConfig extends DhcpL2RelayConfig {
77 @Override
78 public Set<ConnectPoint> getDhcpServerConnectPoint() {
79 return ImmutableSet.of(SERVER_CONNECT_POINT);
80 }
81
82 @Override
83 public boolean getModifySrcDstMacAddresses() {
84 return true;
85 }
86
87 @Override
88 public boolean getUseOltUplinkForServerPktInOut() {
89 return true;
90 }
91 }
92
93 /**
94 * Tests the default configuration.
95 */
96 @Test
97 public void testConfig() {
98 assertThat(dhcpL2Relay.useOltUplink, is(USE_OLT_ULPORT_FOR_PKT_INOUT));
99 assertThat(dhcpL2Relay.modifyClientPktsSrcDstMac, is(MODIFY_SRC_DST_MAC));
100 assertNull(dhcpL2Relay.dhcpServerConnectPoint.get());
101 }
102
103 /**
104 * Tests if dhcpl2relay app has been configured.
105 */
106 @Test
107 public void testDhcpL2RelayConfigured() {
108 assertTrue(dhcpL2Relay.configured());
109 }
110
111 /**
112 * Mocks the network config registry.
113 */
114 @SuppressWarnings("unchecked")
115 static final class TestNetworkConfigRegistry
116 extends NetworkConfigRegistryAdapter {
117 @Override
118 public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
119 DhcpL2RelayConfig dhcpConfig = new MockDhcpL2RelayConfig();
120 return (C) dhcpConfig;
121 }
122 }
123}