Repair Doxygen build infrastructure
[vpp.git] / src / vpp-api / java / jvpp-core / io / fd / vpp / jvpp / core / test / LispAdjacencyTest.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
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  */
16
17 package io.fd.vpp.jvpp.core.test;
18
19 import io.fd.vpp.jvpp.JVppRegistry;
20 import io.fd.vpp.jvpp.JVppRegistryImpl;
21 import io.fd.vpp.jvpp.core.JVppCoreImpl;
22 import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacency;
23 import io.fd.vpp.jvpp.core.dto.LispAddDelLocalEid;
24 import io.fd.vpp.jvpp.core.dto.LispAddDelLocatorSet;
25 import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMapping;
26 import io.fd.vpp.jvpp.core.dto.LispAdjacenciesGet;
27 import io.fd.vpp.jvpp.core.dto.LispAdjacenciesGetReply;
28 import io.fd.vpp.jvpp.core.dto.LispEnableDisable;
29 import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
30 import java.nio.charset.StandardCharsets;
31 import java.util.concurrent.ExecutionException;
32 import java.util.logging.Logger;
33
34 /**
35  * Tests lisp adjacency creation and read (custom vpe.api type support showcase).
36  */
37 public class LispAdjacencyTest {
38
39     private static final Logger LOG = Logger.getLogger(LispAdjacencyTest.class.getName());
40
41     private static void enableLisp(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException {
42         final LispEnableDisable request = new LispEnableDisable();
43         request.isEn = 1;
44         jvpp.lispEnableDisable(request).toCompletableFuture().get();
45         LOG.info("Lisp enabled successfully");
46     }
47
48     private static void addLocatorSet(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException {
49         final LispAddDelLocatorSet request = new LispAddDelLocatorSet();
50         request.isAdd = 1;
51         request.locatorSetName = "ls1".getBytes(StandardCharsets.UTF_8);
52         jvpp.lispAddDelLocatorSet(request).toCompletableFuture().get();
53         LOG.info("Locator set created successfully:" + request.toString());
54     }
55
56     private static void addLocalEid(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException {
57         final LispAddDelLocalEid request = new LispAddDelLocalEid();
58         request.isAdd = 1;
59         request.locatorSetName = "ls1".getBytes(StandardCharsets.UTF_8);
60         request.eid = new byte[] {1, 2, 1, 10};
61         request.eidType = 0; // ip4
62         request.vni = 0;
63         request.prefixLen = 32;
64         jvpp.lispAddDelLocalEid(request).toCompletableFuture().get();
65         LOG.info("Local EID created successfully:" + request.toString());
66     }
67
68     private static void addRemoteMapping(final FutureJVppCoreFacade jvpp)
69         throws ExecutionException, InterruptedException {
70         final LispAddDelRemoteMapping request = new LispAddDelRemoteMapping();
71         request.isAdd = 1;
72         request.vni = 0;
73         request.eid = new byte[] {1, 2, 1, 20};
74         request.eidLen = 32;
75         request.rlocNum = 1;
76         request.rlocs = new byte[] {1, 1, 1, 1, 2, 1, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
77         jvpp.lispAddDelRemoteMapping(request).toCompletableFuture().get();
78         LOG.info("Remote mapping created successfully:" + request.toString());
79     }
80
81     private static void addAdjacency(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException {
82         final LispAddDelAdjacency request = new LispAddDelAdjacency();
83         request.isAdd = 1;
84         request.leid = new byte[] {1, 2, 1, 10};
85         request.leidLen = 32;
86         request.reid = new byte[] {1, 2, 1, 20};
87         request.reidLen = 32;
88         request.eidType = 0; // ip4
89         request.vni = 0;
90         jvpp.lispAddDelAdjacency(request).toCompletableFuture().get();
91         LOG.info("Lisp adjacency created successfully:" + request.toString());
92     }
93
94     private static void showAdjacencies(final FutureJVppCoreFacade jvpp)
95         throws ExecutionException, InterruptedException {
96         final LispAdjacenciesGetReply reply =
97             jvpp.lispAdjacenciesGet(new LispAdjacenciesGet()).toCompletableFuture().get();
98         LOG.info("Lisp adjacency received successfully:" + reply.toString());
99     }
100
101     private static void testAdjacency(final FutureJVppCoreFacade jvpp) throws Exception {
102         enableLisp(jvpp);
103         addLocatorSet(jvpp);
104         addLocalEid(jvpp);
105         addRemoteMapping(jvpp);
106         addAdjacency(jvpp);
107         showAdjacencies(jvpp);
108     }
109
110     private static void testFutureApi() throws Exception {
111         LOG.info("Create lisp adjacency test");
112         try (final JVppRegistry registry = new JVppRegistryImpl("LispAdjacencyTest");
113              final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) {
114             LOG.info("Successfully connected to VPP");
115
116             testAdjacency(jvppFacade);
117             LOG.info("Disconnecting...");
118         }
119     }
120
121     public static void main(String[] args) throws Exception {
122         testFutureApi();
123     }
124 }