blob: 74f6498586155b8e4593ff0d52b309cec6ac9233 [file] [log] [blame]
Charles Chan531a78b2015-12-01 10:00:51 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Charles Chan531a78b2015-12-01 10:00:51 -08003 *
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
17package org.onosproject.segmentrouting.config;
18
19import com.fasterxml.jackson.databind.JsonNode;
20import com.fasterxml.jackson.databind.ObjectMapper;
21import org.junit.Before;
22import org.junit.Test;
23import org.onlab.packet.IpAddress;
24import org.onlab.packet.MacAddress;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.config.Config;
27import org.onosproject.net.config.ConfigApplyDelegate;
28
Charles Chana35b02c2016-02-22 23:02:41 -080029import java.io.InputStream;
Charles Chan531a78b2015-12-01 10:00:51 -080030import java.util.HashMap;
31import java.util.HashSet;
32import java.util.Map;
33import java.util.Set;
34
35import static org.junit.Assert.assertThat;
36import static org.hamcrest.Matchers.is;
37import static org.junit.Assert.assertTrue;
38
39/**
Charles Chan5270ed02016-01-30 23:22:37 -080040 * Tests for class {@link SegmentRoutingDeviceConfig}.
Charles Chan531a78b2015-12-01 10:00:51 -080041 */
Charles Chan5270ed02016-01-30 23:22:37 -080042public class SegmentRoutingDeviceConfigTest {
43 private SegmentRoutingDeviceConfig config;
Charles Chan531a78b2015-12-01 10:00:51 -080044 private Map<Integer, Set<Integer>> adjacencySids1;
45 private Map<Integer, Set<Integer>> adjacencySids2;
46
47 @Before
48 public void setUp() throws Exception {
Charles Chana35b02c2016-02-22 23:02:41 -080049 InputStream jsonStream = SegmentRoutingDeviceConfigTest.class
Charles Chanfc5c7802016-05-17 13:13:55 -070050 .getResourceAsStream("/device.json");
Charles Chan531a78b2015-12-01 10:00:51 -080051
52 adjacencySids1 = new HashMap<>();
53 Set<Integer> ports1 = new HashSet<>();
54 ports1.add(2);
55 ports1.add(3);
56 adjacencySids1.put(100, ports1);
57 Set<Integer> ports2 = new HashSet<>();
58 ports2.add(4);
59 ports2.add(5);
60 adjacencySids1.put(200, ports2);
61
62 adjacencySids2 = new HashMap<>();
63 Set<Integer> ports3 = new HashSet<>();
64 ports3.add(6);
65 adjacencySids2.put(300, ports3);
66
67 DeviceId subject = DeviceId.deviceId("of:0000000000000001");
Charles Chan5270ed02016-01-30 23:22:37 -080068 String key = "segmentrouting";
Charles Chan531a78b2015-12-01 10:00:51 -080069 ObjectMapper mapper = new ObjectMapper();
Charles Chana35b02c2016-02-22 23:02:41 -080070 JsonNode jsonNode = mapper.readTree(jsonStream);
Charles Chan531a78b2015-12-01 10:00:51 -080071 ConfigApplyDelegate delegate = new MockDelegate();
72
Charles Chan5270ed02016-01-30 23:22:37 -080073 config = new SegmentRoutingDeviceConfig();
Charles Chan531a78b2015-12-01 10:00:51 -080074 config.init(subject, key, jsonNode, mapper, delegate);
75 }
76
77 @Test
78 public void testName() throws Exception {
79 assertTrue(config.name().isPresent());
80 assertThat(config.name().get(), is("Leaf-R1"));
81 }
82
83 @Test
84 public void testSetName() throws Exception {
85 config.setName("Spine-R1");
86 assertTrue(config.name().isPresent());
87 assertThat(config.name().get(), is("Spine-R1"));
88 }
89
90 @Test
91 public void testRouterIp() throws Exception {
92 assertThat(config.routerIp(), is(IpAddress.valueOf("10.0.1.254")));
93 }
94
95 @Test
96 public void testSetRouterIp() throws Exception {
97 config.setRouterIp("10.0.2.254");
98 assertThat(config.routerIp(), is(IpAddress.valueOf("10.0.2.254")));
99 }
100
101 @Test
102 public void testRouterMac() throws Exception {
103 assertThat(config.routerMac(), is(MacAddress.valueOf("00:00:00:00:01:80")));
104 }
105
106 @Test
107 public void testSetRouterMac() throws Exception {
108 config.setRouterMac("00:00:00:00:02:80");
109 assertThat(config.routerMac(), is(MacAddress.valueOf("00:00:00:00:02:80")));
110 }
111
112 @Test
113 public void testNodeSid() throws Exception {
114 assertThat(config.nodeSid(), is(101));
115 }
116
117 @Test
118 public void testSetNodeSid() throws Exception {
119 config.setNodeSid(200);
120 assertThat(config.nodeSid(), is(200));
121 }
122
123 @Test
124 public void testIsEdgeRouter() throws Exception {
125 assertThat(config.isEdgeRouter(), is(true));
126 }
127
128 @Test
129 public void testSetIsEdgeRouter() throws Exception {
130 config.setIsEdgeRouter(false);
131 assertThat(config.isEdgeRouter(), is(false));
132 }
133
134 @Test
135 public void testAdjacencySids() throws Exception {
136 assertThat(config.adjacencySids(), is(adjacencySids1));
137 }
138
139 @Test
140 public void testSetAdjacencySids() throws Exception {
141 config.setAdjacencySids(adjacencySids2);
142 assertThat(config.adjacencySids(), is(adjacencySids2));
143 }
144
145 private class MockDelegate implements ConfigApplyDelegate {
146 @Override
147 public void onApply(Config config) {
148 }
149 }
150}