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.v3po.translate.v3po.vppstate;
19 import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.mockMapping;
20 import static org.junit.Assert.assertEquals;
21 import static org.mockito.Matchers.any;
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.verify;
24 import static org.mockito.Mockito.when;
26 import io.fd.honeycomb.v3po.translate.spi.read.ReaderCustomizer;
27 import io.fd.honeycomb.v3po.translate.v3po.test.ListReaderCustomizerTest;
28 import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
29 import java.util.Collections;
30 import java.util.List;
31 import java.util.concurrent.CompletableFuture;
32 import java.util.concurrent.ExecutionException;
33 import org.junit.Test;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.L2FibForward;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.L2FibTable;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.L2FibTableBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntry;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntryKey;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomains;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey;
44 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
45 import org.openvpp.jvpp.VppInvocationException;
46 import org.openvpp.jvpp.dto.L2FibTableDump;
47 import org.openvpp.jvpp.dto.L2FibTableEntry;
48 import org.openvpp.jvpp.dto.L2FibTableEntryReplyDump;
50 public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest<L2FibEntry, L2FibEntryKey, L2FibEntryBuilder> {
52 private static final String BD_NAME = "testBD0";
53 private static final int BD_ID = 111;
54 private static final String IFACE_NAME = "eth0";
55 private static final int IFACE_ID = 123;
56 private static final String BD_CTX_NAME = "bd-test-instance";
57 private static final String IFC_CTX_NAME = "ifc-test-instance";
58 private NamingContext bdContext;
59 private NamingContext interfacesContext;
61 public L2FibEntryCustomizerTest() {
62 super(L2FibEntry.class);
66 public void setUpBefore() {
67 bdContext = new NamingContext("generatedBdName", BD_CTX_NAME);
68 interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
72 protected ReaderCustomizer<L2FibEntry, L2FibEntryBuilder> initCustomizer() {
73 return new L2FibEntryCustomizer(api, bdContext, interfacesContext);
77 public void testMerge() throws Exception {
78 final L2FibTableBuilder builder = mock(L2FibTableBuilder.class);
79 final List<L2FibEntry> value = Collections.emptyList();
80 getCustomizer().merge(builder, value);
81 verify(builder).setL2FibEntry(value);
84 private static InstanceIdentifier<L2FibEntry> getL2FibEntryId(final String bdName, final PhysAddress address) {
85 return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(bdName))
86 .child(L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(address));
89 private void whenL2FibTableDumpThenReturn(final List<L2FibTableEntry> l2FibTableEntryList)
90 throws ExecutionException, InterruptedException, VppInvocationException {
91 final L2FibTableEntryReplyDump reply = new L2FibTableEntryReplyDump();
92 reply.l2FibTableEntry = l2FibTableEntryList;
94 final CompletableFuture<L2FibTableEntryReplyDump> replyFuture = new CompletableFuture<>();
95 replyFuture.complete(reply);
96 when(api.l2FibTableDump(any(L2FibTableDump.class))).thenReturn(replyFuture);
100 public void testRead() throws Exception {
101 final long address_vpp = 0x0000010203040506L;
102 final PhysAddress address = new PhysAddress("01:02:03:04:05:06");
104 mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
105 mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
107 whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp)));
109 final L2FibEntryBuilder builder = mock(L2FibEntryBuilder.class);
110 getCustomizer().readCurrentAttributes(getL2FibEntryId(BD_NAME, address), builder, ctx);
112 verify(builder).setAction(L2FibForward.class);
113 verify(builder).setBridgedVirtualInterface(false);
114 verify(builder).setOutgoingInterface(IFACE_NAME);
115 verify(builder).setStaticConfig(false);
116 verify(builder).setPhysAddress(address);
117 verify(builder).setKey(new L2FibEntryKey(address));
120 private L2FibTableEntry generateL2FibEntry(final long mac) {
121 final L2FibTableEntry entry = new L2FibTableEntry();
123 entry.swIfIndex = IFACE_ID;
128 public void testGetAllIds() throws Exception {
129 final long address_vpp = 0x0000112233445566L;
130 final PhysAddress address = new PhysAddress("11:22:33:44:55:66");
131 mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
133 whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp)));
135 final List<L2FibEntryKey> ids = getCustomizer().getAllIds(getL2FibEntryId(BD_NAME, address), ctx);
136 assertEquals(1, ids.size());
137 assertEquals(address, ids.get(0).getPhysAddress());