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.Ipv4Translator;
30 import io.fd.honeycomb.translate.write.WriteFailedException;
31 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
32 import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMapping;
33 import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMappingReply;
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.MapReplyAction;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappings;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingKey;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.NegativeMappingBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.negative.mapping.MapReplyBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData;
57 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
59 public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements Ipv4Translator {
62 private ArgumentCaptor<LispAddDelRemoteMapping> mappingCaptor;
64 private MappingId mappingId;
65 private RemoteMappingCustomizer customizer;
66 private RemoteMapping intf;
67 private InstanceIdentifier<RemoteMapping> id;
70 private EidMappingContext remoteMappingContext;
74 final Eid eid = new EidBuilder()
75 .setAddressType(Ipv4Afi.class)
77 new Ipv4Builder().setIpv4(
78 new Ipv4Address("192.168.2.1"))
82 mappingId = new MappingId("REMOTE");
83 final RemoteMappingKey key = new RemoteMappingKey(mappingId);
85 intf = new RemoteMappingBuilder()
88 .setLocatorList(new NegativeMappingBuilder()
89 .setMapReply(new MapReplyBuilder().setMapReplyAction(MapReplyAction.Drop).build()).build())
92 id = InstanceIdentifier.builder(Lisp.class)
93 .child(LispFeatureData.class)
94 .child(EidTable.class)
95 .child(VniTable.class, new VniTableKey(25L))
96 .child(VrfSubtable.class)
97 .child(RemoteMappings.class)
98 .child(RemoteMapping.class, key).build();
100 customizer = new RemoteMappingCustomizer(api, remoteMappingContext);
102 when(api.lispAddDelRemoteMapping(any())).thenReturn(future(new LispAddDelRemoteMappingReply()));
105 @Test(expected = NullPointerException.class)
106 public void testWriteCurrentAttributesNullData() throws WriteFailedException {
107 customizer.writeCurrentAttributes(null, null, writeContext);
110 @Test(expected = NullPointerException.class)
111 public void testWriteCurrentAttributesBadData() throws WriteFailedException {
113 .writeCurrentAttributes(null, mock(RemoteMapping.class), writeContext);
117 public void testWriteCurrentAttributes() throws WriteFailedException {
118 customizer.writeCurrentAttributes(id, intf, writeContext);
120 verify(api, times(1)).lispAddDelRemoteMapping(mappingCaptor.capture());
122 LispAddDelRemoteMapping request = mappingCaptor.getValue();
124 assertNotNull(request);
125 assertEquals(1, request.isAdd);
126 assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.eid).getValue());
127 assertEquals(25, request.vni);
130 @Test(expected = UnsupportedOperationException.class)
131 public void testUpdateCurrentAttributes() throws WriteFailedException {
132 customizer.updateCurrentAttributes(null, null, null, writeContext);
135 @Test(expected = NullPointerException.class)
136 public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
137 customizer.deleteCurrentAttributes(null, null, writeContext);
141 public void testDeleteCurrentAttributes() throws WriteFailedException {
142 when(remoteMappingContext.containsEid(any(), eq(mappingContext))).thenReturn(true);
143 customizer.deleteCurrentAttributes(id, intf, writeContext);
145 verify(api, times(1)).lispAddDelRemoteMapping(mappingCaptor.capture());
147 LispAddDelRemoteMapping request = mappingCaptor.getValue();
149 assertNotNull(request);
150 assertEquals(0, request.isAdd);
151 assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.eid).getValue());
152 assertEquals(25, request.vni);