blob: c53037de1e1c2ab288315a5a318e44fdcf056b3c [file] [log] [blame]
Charles Chand55e84d2016-03-30 17:54:24 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Charles Chand55e84d2016-03-30 17:54:24 -07003 *
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
Ray Milkeyd29bc1c2018-03-13 11:57:11 -070017package org.onosproject.net.config.basics;
Charles Chand55e84d2016-03-30 17:54:24 -070018
19import com.fasterxml.jackson.databind.JsonNode;
20import com.fasterxml.jackson.databind.ObjectMapper;
21import com.google.common.annotations.Beta;
22import org.junit.Before;
23import org.junit.Test;
24import org.onlab.packet.VlanId;
25import org.onosproject.TestApplicationId;
26import org.onosproject.core.ApplicationId;
27import org.onosproject.core.CoreService;
28import org.onosproject.net.config.Config;
29import org.onosproject.net.config.ConfigApplyDelegate;
30
31import java.io.InputStream;
32
33import static org.hamcrest.Matchers.is;
Ray Milkeyd29bc1c2018-03-13 11:57:11 -070034import static org.junit.Assert.assertFalse;
35import static org.junit.Assert.assertNotNull;
36import static org.junit.Assert.assertThat;
37import static org.junit.Assert.assertTrue;
Charles Chand55e84d2016-03-30 17:54:24 -070038
39/**
40 * Tests for class {@link McastConfig}.
41 */
42@Beta
43public class McastConfigTest {
44 private static final TestApplicationId APP_ID =
45 new TestApplicationId(CoreService.CORE_APP_NAME);
46 private McastConfig config;
47 private McastConfig invalidConfig;
Esin Karaman66f8c612020-03-12 14:22:46 +000048 private McastConfig configForInnerVlan;
49 private McastConfig invalidConfigForInnerVlan;
Charles Chand55e84d2016-03-30 17:54:24 -070050
51 private static final VlanId INGRESS_VLAN_1 = VlanId.NONE;
52 private static final VlanId EGRESS_VLAN_1 = VlanId.NONE;
Esin Karaman66f8c612020-03-12 14:22:46 +000053 private static final VlanId EGRESS_INNER_VLAN_1 = VlanId.NONE;
Charles Chand55e84d2016-03-30 17:54:24 -070054 private static final VlanId INGRESS_VLAN_2 = VlanId.vlanId((short) 100);
55 private static final VlanId EGRESS_VLAN_2 = VlanId.vlanId((short) 100);
Esin Karaman66f8c612020-03-12 14:22:46 +000056 private static final VlanId EGRESS_INNER_VLAN_2 = VlanId.vlanId((short) 100);
Charles Chand55e84d2016-03-30 17:54:24 -070057
58 /**
59 * Initialize test related variables.
60 *
61 * @throws Exception
62 */
63 @Before
64 public void setUp() throws Exception {
65 InputStream jsonStream = McastConfigTest.class
66 .getResourceAsStream("/mcast-config.json");
67 InputStream invalidJsonStream = McastConfigTest.class
68 .getResourceAsStream("/mcast-config-invalid.json");
Esin Karaman66f8c612020-03-12 14:22:46 +000069 InputStream jsonStreamForInnerVlan = McastConfigTest.class
70 .getResourceAsStream("/mcast-config-inner.json");
71 InputStream invalidJsonStreamForInnerVlan = McastConfigTest.class
72 .getResourceAsStream("/mcast-config-invalid-inner.json");
Charles Chand55e84d2016-03-30 17:54:24 -070073
74 ApplicationId subject = APP_ID;
75 String key = CoreService.CORE_APP_NAME;
76 ObjectMapper mapper = new ObjectMapper();
77 JsonNode jsonNode = mapper.readTree(jsonStream);
78 JsonNode invalidJsonNode = mapper.readTree(invalidJsonStream);
Esin Karaman66f8c612020-03-12 14:22:46 +000079 JsonNode jsonNodeForInnerVlan = mapper.readTree(jsonStreamForInnerVlan);
80 JsonNode invalidJsonNodeForInnerVlan = mapper.readTree(invalidJsonStreamForInnerVlan);
Charles Chand55e84d2016-03-30 17:54:24 -070081 ConfigApplyDelegate delegate = new MockDelegate();
82
83 config = new McastConfig();
84 config.init(subject, key, jsonNode, mapper, delegate);
85 invalidConfig = new McastConfig();
86 invalidConfig.init(subject, key, invalidJsonNode, mapper, delegate);
Esin Karaman66f8c612020-03-12 14:22:46 +000087 configForInnerVlan = new McastConfig();
88 configForInnerVlan.init(subject, key, jsonNodeForInnerVlan, mapper, delegate);
89 invalidConfigForInnerVlan = new McastConfig();
90 invalidConfigForInnerVlan.init(subject, key, invalidJsonNodeForInnerVlan, mapper, delegate);
Charles Chand55e84d2016-03-30 17:54:24 -070091 }
92
93 /**
94 * Tests config validity.
95 *
96 * @throws Exception
97 */
98 @Test
99 public void isValid() throws Exception {
100 assertTrue(config.isValid());
101 assertFalse(invalidConfig.isValid());
Esin Karaman66f8c612020-03-12 14:22:46 +0000102 assertTrue(configForInnerVlan.isValid());
103 assertFalse(invalidConfigForInnerVlan.isValid());
Charles Chand55e84d2016-03-30 17:54:24 -0700104 }
105
106 /**
107 * Tests ingress VLAN getter.
108 *
109 * @throws Exception
110 */
111 @Test
112 public void ingressVlan() throws Exception {
113 VlanId ingressVlan = config.ingressVlan();
114 assertNotNull("ingressVlan should not be null", ingressVlan);
115 assertThat(ingressVlan, is(INGRESS_VLAN_1));
116 }
117
118 /**
119 * Tests ingress VLAN setter.
120 *
121 * @throws Exception
122 */
123 @Test
124 public void setIngressVlan() throws Exception {
125 config.setIngressVlan(INGRESS_VLAN_2);
126
127 VlanId ingressVlan = config.ingressVlan();
128 assertNotNull("ingressVlan should not be null", ingressVlan);
129 assertThat(ingressVlan, is(INGRESS_VLAN_2));
130 }
131
132 /**
133 * Tests egress VLAN getter.
134 *
135 * @throws Exception
136 */
137 @Test
138 public void egressVlan() throws Exception {
139 VlanId egressVlan = config.egressVlan();
140 assertNotNull("egressVlan should not be null", egressVlan);
141 assertThat(egressVlan, is(EGRESS_VLAN_1));
142 }
143
144 /**
145 * Tests egress VLAN setter.
146 *
147 * @throws Exception
148 */
149 @Test
150 public void setEgressVlan() throws Exception {
151 config.setEgressVlan(EGRESS_VLAN_2);
152
153 VlanId egressVlan = config.egressVlan();
154 assertNotNull("egressVlan should not be null", egressVlan);
155 assertThat(egressVlan, is(EGRESS_VLAN_2));
156 }
157
Esin Karaman66f8c612020-03-12 14:22:46 +0000158 /**
159 * Tests egress inner VLAN getter.
160 *
161 * @throws Exception
162 */
163 @Test
164 public void egressInnerVlan() {
165 VlanId egressInnerVlan = config.egressInnerVlan();
166 assertNotNull("egressInnerVlan should not be null", egressInnerVlan);
167 assertThat(egressInnerVlan, is(EGRESS_INNER_VLAN_1));
168 }
169
170
171 /**
172 * Tests egress inner VLAN setter.
173 *
174 * @throws Exception
175 */
176 @Test
177 public void setEgressInnerVlan() {
178 config.setEgressInnerVlan(EGRESS_INNER_VLAN_2);
179
180 VlanId egressInnerVlan = config.egressInnerVlan();
181 assertNotNull("egressInnerVlan should not be null", egressInnerVlan);
182 assertThat(egressInnerVlan, is(EGRESS_INNER_VLAN_2));
183 }
184
Charles Chand55e84d2016-03-30 17:54:24 -0700185 private class MockDelegate implements ConfigApplyDelegate {
186 @Override
187 public void onApply(Config config) {
188 }
189 }
Ray Milkey6c1f0f02017-08-15 11:02:29 -0700190}