2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.lisp.translate.read;
19 import static io.fd.honeycomb.lisp.translate.AdjacencyData.ADDRESS_ONE;
20 import static io.fd.honeycomb.lisp.translate.AdjacencyData.ADDRESS_THREE;
21 import static io.fd.honeycomb.lisp.translate.AdjacencyData.LOCAL_EID_ONE;
22 import static io.fd.honeycomb.lisp.translate.AdjacencyData.LOCAL_EID_TWO;
23 import static io.fd.honeycomb.lisp.translate.AdjacencyData.REMOTE_EID_ONE;
24 import static io.fd.honeycomb.lisp.translate.AdjacencyData.REMOTE_EID_TWO;
25 import static org.hamcrest.MatcherAssert.assertThat;
26 import static org.hamcrest.Matchers.contains;
27 import static org.hamcrest.Matchers.hasSize;
28 import static org.junit.Assert.assertEquals;
29 import static org.mockito.Matchers.any;
30 import static org.mockito.Mockito.when;
32 import io.fd.honeycomb.lisp.context.util.AdjacenciesMappingContext;
33 import io.fd.honeycomb.lisp.context.util.EidMappingContext;
34 import io.fd.honeycomb.lisp.translate.util.EidMetadataProvider;
35 import io.fd.honeycomb.lisp.util.AdjacencyMappingContextTestHelper;
36 import io.fd.honeycomb.lisp.util.EidMappingContextHelper;
37 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
38 import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
39 import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
40 import io.fd.vpp.jvpp.core.dto.LispAdjacenciesGetReply;
41 import io.fd.vpp.jvpp.core.types.LispAdjacency;
42 import java.util.List;
43 import org.junit.Before;
44 import org.junit.Test;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.MappingId;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.Adjacencies;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.AdjacenciesBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.adjacencies.Adjacency;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.adjacencies.AdjacencyBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.adjacencies.AdjacencyKey;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.RemoteMappings;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.RemoteMapping;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.RemoteMappingKey;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.EidTable;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTable;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTableKey;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable;
59 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
62 public class AdjacencyCustomizerTest
63 extends ListReaderCustomizerTest<Adjacency, AdjacencyKey, AdjacencyBuilder>
64 implements ByteDataTranslator, EidMetadataProvider, EidMappingContextHelper, AdjacencyMappingContextTestHelper {
66 private InstanceIdentifier<Adjacency> identifier;
68 public AdjacencyCustomizerTest() {
69 super(Adjacency.class, AdjacenciesBuilder.class);
74 identifier = InstanceIdentifier.create(EidTable.class)
75 .child(VniTable.class, new VniTableKey(2L))
76 .child(BridgeDomainSubtable.class)
77 .child(RemoteMappings.class)
78 .child(RemoteMapping.class, new RemoteMappingKey(new MappingId("remote-mapping")))
79 .child(Adjacencies.class)
80 .child(Adjacency.class, new AdjacencyKey("adj-one"));
84 defineEidMapping(mappingContext, LOCAL_EID_ONE, new MappingId("local-eid-one"), "local-mapping-context");
85 defineEidMapping(mappingContext, LOCAL_EID_TWO, new MappingId("local-eid-two"), "local-mapping-context");
86 defineEidMapping(mappingContext, REMOTE_EID_ONE, new MappingId("remote-eid-one"), "remote-mapping-context");
87 defineEidMapping(mappingContext, REMOTE_EID_TWO, new MappingId("remote-eid-two"), "remote-mapping-context");
89 defineAdjacencyMapping(mappingContext, "local-eid-one", "remote-eid-one", "adj-one",
90 "adjacencies-mapping-context");
91 defineAdjacencyMapping(mappingContext, "local-eid-two", "remote-eid-two", "adj-two",
92 "adjacencies-mapping-context");
97 public void getAllIds() throws Exception {
98 final List<AdjacencyKey> keys = getCustomizer().getAllIds(identifier, ctx);
100 assertThat(keys, hasSize(2));
101 assertThat(keys, contains(new AdjacencyKey("adj-one"), new AdjacencyKey("adj-two")));
105 public void readCurrentAttributes() throws Exception {
106 final AdjacencyBuilder builder = new AdjacencyBuilder();
107 getCustomizer().readCurrentAttributes(identifier, builder, ctx);
109 assertEquals("adj-one", builder.getId());
110 assertEquals(new AdjacencyKey("adj-one"), builder.getKey());
111 assertEquals(ADDRESS_ONE.getValue(), Ipv4.class.cast(builder.getLocalEid().getAddress()).getIpv4().getValue());
112 assertEquals(ADDRESS_THREE.getValue(),
113 Ipv4.class.cast(builder.getRemoteEid().getAddress()).getIpv4().getValue());
117 protected ReaderCustomizer<Adjacency, AdjacencyBuilder> initCustomizer() {
118 return new AdjacencyCustomizer(api, new EidMappingContext("local-mapping-context"),
119 new EidMappingContext("remote-mapping-context"),
120 new AdjacenciesMappingContext("adjacencies-mapping-context"));
124 private void mockApi() {
125 LispAdjacency adjacencyOne = new LispAdjacency();
126 adjacencyOne.eidType = 0;
127 adjacencyOne.leid = new byte[]{-64, -88, 2, 1};
128 adjacencyOne.leidPrefixLen = 32;
129 adjacencyOne.reid = new byte[]{-64, -88, 2, 3};
130 adjacencyOne.reidPrefixLen = 32;
133 LispAdjacency adjacencyTwo = new LispAdjacency();
134 adjacencyTwo.eidType = 0;
135 adjacencyTwo.leid = new byte[]{-64, -88, 2, 2};
136 adjacencyTwo.leidPrefixLen = 32;
137 adjacencyTwo.reid = new byte[]{-64, -88, 2, 4};
138 adjacencyTwo.reidPrefixLen = 32;
140 LispAdjacenciesGetReply reply = new LispAdjacenciesGetReply();
141 reply.adjacencies = new LispAdjacency[]{adjacencyOne, adjacencyTwo};
143 when(api.lispAdjacenciesGet(any())).thenReturn(future(reply));