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.vpp.jvpp.core.examples;
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;
35 * Tests lisp adjacency creation and read (custom vpe.api type support showcase).
37 public class LispAdjacencyExample {
39 private static final Logger LOG = Logger.getLogger(LispAdjacencyExample.class.getName());
41 private static void enableLisp(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException {
42 final LispEnableDisable request = new LispEnableDisable();
44 jvpp.lispEnableDisable(request).toCompletableFuture().get();
45 LOG.info("Lisp enabled successfully");
48 private static void addLocatorSet(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException {
49 final LispAddDelLocatorSet request = new LispAddDelLocatorSet();
51 request.locatorSetName = "ls1".getBytes(StandardCharsets.UTF_8);
52 jvpp.lispAddDelLocatorSet(request).toCompletableFuture().get();
53 LOG.info("Locator set created successfully:" + request.toString());
56 private static void addLocalEid(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException {
57 final LispAddDelLocalEid request = new LispAddDelLocalEid();
59 request.locatorSetName = "ls1".getBytes(StandardCharsets.UTF_8);
60 request.eid = new byte[] {1, 2, 1, 10};
61 request.eidType = 0; // ip4
63 request.prefixLen = 32;
64 jvpp.lispAddDelLocalEid(request).toCompletableFuture().get();
65 LOG.info("Local EID created successfully:" + request.toString());
68 private static void addRemoteMapping(final FutureJVppCoreFacade jvpp)
69 throws ExecutionException, InterruptedException {
70 final LispAddDelRemoteMapping request = new LispAddDelRemoteMapping();
73 request.eid = new byte[] {1, 2, 1, 20};
77 //request.rlocs = new byte[] {1, 1, 1, 1, 2, 1, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
78 jvpp.lispAddDelRemoteMapping(request).toCompletableFuture().get();
79 LOG.info("Remote mapping created successfully:" + request.toString());
82 private static void addAdjacency(final FutureJVppCoreFacade jvpp) throws ExecutionException, InterruptedException {
83 final LispAddDelAdjacency request = new LispAddDelAdjacency();
85 request.leid = new byte[] {1, 2, 1, 10};
87 request.reid = new byte[] {1, 2, 1, 20};
89 request.eidType = 0; // ip4
91 jvpp.lispAddDelAdjacency(request).toCompletableFuture().get();
92 LOG.info("Lisp adjacency created successfully:" + request.toString());
95 private static void showAdjacencies(final FutureJVppCoreFacade jvpp)
96 throws ExecutionException, InterruptedException {
97 final LispAdjacenciesGetReply reply =
98 jvpp.lispAdjacenciesGet(new LispAdjacenciesGet()).toCompletableFuture().get();
99 LOG.info("Lisp adjacency received successfully:" + reply.toString());
102 private static void testAdjacency(final FutureJVppCoreFacade jvpp) throws Exception {
106 addRemoteMapping(jvpp);
108 showAdjacencies(jvpp);
111 private static void testFutureApi() throws Exception {
112 LOG.info("Create lisp adjacency test");
113 try (final JVppRegistry registry = new JVppRegistryImpl("LispAdjacencyExample");
114 final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl())) {
115 LOG.info("Successfully connected to VPP");
117 testAdjacency(jvppFacade);
118 LOG.info("Disconnecting...");
122 public static void main(String[] args) throws Exception {