blob: 469ce502ad9b03a66b130fb3aff3e6a10e55de9b [file] [log] [blame]
Jian Li18f3bce2016-08-04 17:36:41 +09001/*
2 * Copyright 2016-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.lisp.msg.protocols;
17
Jian Lie4ba2a42016-08-29 20:24:15 +090018import com.google.common.collect.ImmutableList;
Jian Li18f3bce2016-08-04 17:36:41 +090019import com.google.common.testing.EqualsTester;
Jian Lie4ba2a42016-08-29 20:24:15 +090020import io.netty.buffer.ByteBuf;
21import io.netty.buffer.Unpooled;
Jian Li18f3bce2016-08-04 17:36:41 +090022import org.junit.Before;
23import org.junit.Test;
Jian Lie4ba2a42016-08-29 20:24:15 +090024import org.onlab.packet.IpAddress;
25import org.onosproject.lisp.msg.exceptions.LispParseError;
26import org.onosproject.lisp.msg.exceptions.LispReaderException;
27import org.onosproject.lisp.msg.exceptions.LispWriterException;
28import org.onosproject.lisp.msg.types.LispAfiAddress;
29import org.onosproject.lisp.msg.types.LispIpv4Address;
30
31import java.util.List;
Jian Li18f3bce2016-08-04 17:36:41 +090032
33import static org.hamcrest.MatcherAssert.assertThat;
34import static org.hamcrest.Matchers.is;
Jian Lie4ba2a42016-08-29 20:24:15 +090035import static org.onosproject.lisp.msg.protocols.DefaultLispMapRequest.*;
Jian Li18f3bce2016-08-04 17:36:41 +090036
37/**
38 * Unit tests for DefaultLispMapRequest class.
39 */
Jian Li47671902016-08-11 01:18:18 +090040public final class DefaultLispMapRequestTest {
Jian Li18f3bce2016-08-04 17:36:41 +090041
42 private LispMapRequest request1;
43 private LispMapRequest sameAsRequest1;
44 private LispMapRequest request2;
45
46 @Before
47 public void setup() {
48
Jian Lie4ba2a42016-08-29 20:24:15 +090049 RequestBuilder builder1 = new DefaultRequestBuilder();
50
51 LispIpv4Address ipv4Eid1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
52
53 LispIpv4Address ipv4Rloc1 = new LispIpv4Address(IpAddress.valueOf("10.1.1.1"));
54 LispIpv4Address ipv4Rloc2 = new LispIpv4Address(IpAddress.valueOf("10.1.1.2"));
55
56 List<LispAfiAddress> rlocs1 = ImmutableList.of(ipv4Rloc1, ipv4Rloc2);
Jian Li18f3bce2016-08-04 17:36:41 +090057
58 request1 = builder1
59 .withIsAuthoritative(true)
60 .withIsMapDataPresent(true)
61 .withIsPitr(false)
62 .withIsProbe(false)
63 .withIsSmr(true)
64 .withIsSmrInvoked(false)
Jian Lie4ba2a42016-08-29 20:24:15 +090065 .withSourceEid(ipv4Eid1)
66 .withItrRlocs(rlocs1)
Jian Li18f3bce2016-08-04 17:36:41 +090067 .withNonce(1L)
Jian Li18f3bce2016-08-04 17:36:41 +090068 .build();
69
Jian Lie4ba2a42016-08-29 20:24:15 +090070 RequestBuilder builder2 = new DefaultRequestBuilder();
Jian Li18f3bce2016-08-04 17:36:41 +090071
72 sameAsRequest1 = builder2
73 .withIsAuthoritative(true)
74 .withIsMapDataPresent(true)
75 .withIsPitr(false)
76 .withIsProbe(false)
77 .withIsSmr(true)
78 .withIsSmrInvoked(false)
Jian Lie4ba2a42016-08-29 20:24:15 +090079 .withSourceEid(ipv4Eid1)
80 .withItrRlocs(rlocs1)
Jian Li18f3bce2016-08-04 17:36:41 +090081 .withNonce(1L)
Jian Li18f3bce2016-08-04 17:36:41 +090082 .build();
83
Jian Lie4ba2a42016-08-29 20:24:15 +090084 RequestBuilder builder3 = new DefaultRequestBuilder();
85
86 LispIpv4Address ipv4Eid2 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2"));
87
88 LispIpv4Address ipv4Rloc3 = new LispIpv4Address(IpAddress.valueOf("10.1.1.1"));
89 LispIpv4Address ipv4Rloc4 = new LispIpv4Address(IpAddress.valueOf("10.1.1.2"));
90
91 List<LispAfiAddress> rlocs2 = ImmutableList.of(ipv4Rloc3, ipv4Rloc4);
Jian Li18f3bce2016-08-04 17:36:41 +090092
93 request2 = builder3
94 .withIsAuthoritative(false)
95 .withIsMapDataPresent(false)
96 .withIsPitr(true)
97 .withIsProbe(true)
98 .withIsSmr(false)
99 .withIsSmrInvoked(true)
Jian Lie4ba2a42016-08-29 20:24:15 +0900100 .withSourceEid(ipv4Eid2)
101 .withItrRlocs(rlocs2)
Jian Li18f3bce2016-08-04 17:36:41 +0900102 .withNonce(2L)
Jian Li18f3bce2016-08-04 17:36:41 +0900103 .build();
104 }
105
106 @Test
107 public void testEquality() {
108 new EqualsTester()
109 .addEqualityGroup(request1, sameAsRequest1)
110 .addEqualityGroup(request2).testEquals();
111 }
112
113 @Test
114 public void testConstruction() {
115 DefaultLispMapRequest request = (DefaultLispMapRequest) request1;
116
117 assertThat(request.isAuthoritative(), is(true));
118 assertThat(request.isMapDataPresent(), is(true));
119 assertThat(request.isPitr(), is(false));
120 assertThat(request.isProbe(), is(false));
121 assertThat(request.isSmr(), is(true));
122 assertThat(request.isSmrInvoked(), is(false));
123 assertThat(request.getNonce(), is(1L));
Jian Lie4ba2a42016-08-29 20:24:15 +0900124 }
125
126 @Test
127 public void testSerialization() throws LispReaderException, LispWriterException, LispParseError {
128 ByteBuf byteBuf = Unpooled.buffer();
129 RequestWriter writer = new RequestWriter();
130 writer.writeTo(byteBuf, request1);
131
132 RequestReader reader = new RequestReader();
133 LispMapRequest deserialized = reader.readFrom(byteBuf);
134
135 new EqualsTester()
136 .addEqualityGroup(request1, deserialized).testEquals();
Jian Li18f3bce2016-08-04 17:36:41 +0900137 }
138}