2 * Copyright (c) 2015 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.write;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21 import static org.mockito.Matchers.any;
22 import static org.mockito.Matchers.eq;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.times;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
28 import io.fd.honeycomb.lisp.context.util.EidMappingContext;
29 import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
30 import io.fd.honeycomb.translate.vpp.util.Ipv4Translator;
31 import io.fd.honeycomb.translate.write.WriteFailedException;
32 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
33 import java.util.concurrent.ExecutionException;
34 import org.junit.Test;
35 import org.mockito.ArgumentCaptor;
36 import org.mockito.Captor;
37 import org.mockito.Mock;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappings;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingKey;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData;
54 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
55 import io.fd.vpp.jvpp.core.dto.LispAddDelLocalEid;
56 import io.fd.vpp.jvpp.core.dto.LispAddDelLocalEidReply;
58 public class LocalMappingCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator, Ipv4Translator {
61 private EidMappingContext eidMappingContext;
63 private ArgumentCaptor<LispAddDelLocalEid> mappingCaptor;
65 private InstanceIdentifier<LocalMapping> id;
66 private LocalMapping mapping;
67 private LocalMappingCustomizer customizer;
72 eid = new EidBuilder()
73 .setAddressType(Ipv4Afi.class)
75 new Ipv4Builder().setIpv4(
76 new Ipv4Address("192.168.2.1"))
80 mapping = new LocalMappingBuilder()
82 .setLocatorSet("Locator")
85 id = InstanceIdentifier.builder(Lisp.class)
86 .child(LispFeatureData.class)
87 .child(EidTable.class)
88 .child(VniTable.class, new VniTableKey(25L))
89 .child(VrfSubtable.class)
90 .child(LocalMappings.class)
91 .child(LocalMapping.class, new LocalMappingKey(new MappingId("local")))
94 customizer = new LocalMappingCustomizer(api, eidMappingContext);
96 when(api.lispAddDelLocalEid(any(LispAddDelLocalEid.class))).thenReturn(future(new LispAddDelLocalEidReply()));
100 @Test(expected = NullPointerException.class)
101 public void testWriteCurrentAttributesNullData() throws WriteFailedException {
102 customizer.writeCurrentAttributes(null, null, writeContext);
105 @Test(expected = NullPointerException.class)
106 public void testWriteCurrentAttributesNullEid() throws WriteFailedException {
107 LocalMapping mapping = mock(LocalMapping.class);
108 when(mapping.getEid()).thenReturn(null);
109 when(mapping.getLocatorSet()).thenReturn("Locator");
111 customizer.writeCurrentAttributes(null, mapping, writeContext);
114 @Test(expected = NullPointerException.class)
115 public void testWriteCurrentAttributesNullLocator() throws WriteFailedException {
116 LocalMapping mapping = mock(LocalMapping.class);
117 when(mapping.getEid()).thenReturn(mock(Eid.class));
118 when(mapping.getLocatorSet()).thenReturn(null);
120 customizer.writeCurrentAttributes(null, mapping, writeContext);
125 public void testWriteCurrentAttributes() throws WriteFailedException {
126 customizer.writeCurrentAttributes(id, mapping, writeContext);
128 verify(api, times(1)).lispAddDelLocalEid(mappingCaptor.capture());
130 LispAddDelLocalEid request = mappingCaptor.getValue();
132 assertNotNull(request);
133 assertEquals("Locator", new String(request.locatorSetName));
134 assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.eid).getValue());
135 assertEquals(0, request.eidType);
136 assertEquals(1, request.isAdd);
137 assertEquals(25, request.vni);
138 assertEquals("Locator", toString(request.locatorSetName));
141 @Test(expected = UnsupportedOperationException.class)
142 public void testUpdateCurrentAttributes() throws WriteFailedException {
143 customizer.updateCurrentAttributes(null, null, null, writeContext);
147 public void testDeleteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
148 when(eidMappingContext.containsEid(any(), eq(mappingContext))).thenReturn(true);
149 customizer.deleteCurrentAttributes(id, mapping, writeContext);
151 verify(api, times(1)).lispAddDelLocalEid(mappingCaptor.capture());
153 LispAddDelLocalEid request = mappingCaptor.getValue();
155 assertNotNull(request);
156 assertEquals("Locator", new String(request.locatorSetName));
157 assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.eid).getValue());
158 assertEquals(0, request.eidType);
159 assertEquals(0, request.isAdd);
160 assertEquals(25, request.vni);
161 assertEquals("Locator", toString(request.locatorSetName));