blob: bbb3da539f234386b01abd412839457ccf006c0d [file] [log] [blame]
Jian Li299bc1d2017-03-17 19:17:40 +09001/*
2 * Copyright 2017-present Open Networking Laboratory
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.onosproject.drivers.lisp.extensions;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Before;
20import org.junit.Test;
21import org.onlab.packet.IpPrefix;
22import org.onosproject.mapping.addresses.MappingAddress;
23import org.onosproject.mapping.addresses.MappingAddresses;
24
25import static org.hamcrest.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.is;
27
28/**
29 * Unit tests for LispAppDataAddress extension class.
30 */
31public class LispAppDataAddressTest {
32
33 private static final IpPrefix IP_ADDRESS_1 = IpPrefix.valueOf("1.2.3.4/24");
34 private static final IpPrefix IP_ADDRESS_2 = IpPrefix.valueOf("5.6.7.8/24");
35
36 private static final byte PROTOCOL_VALUE_1 = 0x01;
37 private static final int IP_TOS_VALUE_1 = 10;
38 private static final short LOCAL_PORT_LOW_VALUE = 1;
39 private static final short LOCAL_PORT_HIGH_VALUE = 255;
40 private static final short REMOTE_PORT_LOW_VALUE = 2;
41 private static final short REMOTE_PORT_HIGH_VALUE = 254;
42
43 private static final byte PROTOCOL_VALUE_2 = 0x02;
44 private static final int IP_TOS_VALUE_2 = 20;
45
46 private LispAppDataAddress address1;
47 private LispAppDataAddress sameAsAddress1;
48 private LispAppDataAddress address2;
49
50 @Before
51 public void setUp() {
52
53 MappingAddress ma1 = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_1);
54
55 address1 = new LispAppDataAddress.Builder()
56 .withProtocol(PROTOCOL_VALUE_1)
57 .withIpTos(IP_TOS_VALUE_1)
58 .withLocalPortLow(LOCAL_PORT_LOW_VALUE)
59 .withLocalPortHigh(LOCAL_PORT_HIGH_VALUE)
60 .withRemotePortLow(REMOTE_PORT_LOW_VALUE)
61 .withRemotePortHigh(REMOTE_PORT_HIGH_VALUE)
62 .withAddress(ma1)
63 .build();
64
65 sameAsAddress1 = new LispAppDataAddress.Builder()
66 .withProtocol(PROTOCOL_VALUE_1)
67 .withIpTos(IP_TOS_VALUE_1)
68 .withLocalPortLow(LOCAL_PORT_LOW_VALUE)
69 .withLocalPortHigh(LOCAL_PORT_HIGH_VALUE)
70 .withRemotePortLow(REMOTE_PORT_LOW_VALUE)
71 .withRemotePortHigh(REMOTE_PORT_HIGH_VALUE)
72 .withAddress(ma1)
73 .build();
74
75 MappingAddress ma2 = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_2);
76
77 address2 = new LispAppDataAddress.Builder()
78 .withProtocol(PROTOCOL_VALUE_2)
79 .withIpTos(IP_TOS_VALUE_2)
80 .withLocalPortLow(LOCAL_PORT_LOW_VALUE)
81 .withLocalPortHigh(LOCAL_PORT_HIGH_VALUE)
82 .withRemotePortLow(REMOTE_PORT_LOW_VALUE)
83 .withRemotePortHigh(REMOTE_PORT_HIGH_VALUE)
84 .withAddress(ma2)
85 .build();
86 }
87
88 @Test
89 public void testEquality() {
90 new EqualsTester()
91 .addEqualityGroup(address1, sameAsAddress1)
92 .addEqualityGroup(address2).testEquals();
93 }
94
95 @Test
96 public void testConstruction() {
97 LispAppDataAddress address = address1;
98
99 MappingAddress ma = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_1);
100
101 assertThat(address.getProtocol(), is(PROTOCOL_VALUE_1));
102 assertThat(address.getIpTos(), is(IP_TOS_VALUE_1));
103 assertThat(address.getLocalPortLow(), is(LOCAL_PORT_LOW_VALUE));
104 assertThat(address.getLocalPortHigh(), is(LOCAL_PORT_HIGH_VALUE));
105 assertThat(address.getRemotePortLow(), is(REMOTE_PORT_LOW_VALUE));
106 assertThat(address.getRemotePortHigh(), is(REMOTE_PORT_HIGH_VALUE));
107 assertThat(address.getAddress(), is(ma));
108 }
109
110 @Test
111 public void testSerialization() {
112 LispAppDataAddress other = new LispAppDataAddress();
113 other.deserialize(address1.serialize());
114
115 new EqualsTester()
116 .addEqualityGroup(address1, other)
117 .testEquals();
118 }
119}