delete loopback interface cli
[vpp.git] / vpp-api / java / japi / test / demo.java
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 import org.openvpp.vppjapi.*;
17
18 public class demo {
19     public static void main (String[] args) throws Exception {
20         vppApi api = new vppApi ("JavaTest");
21         System.out.printf ("Connected OK...");
22
23         String intlist;
24         int [] contexts;
25         int i, limit;
26         int trips;
27         int rv, errors, saved_error;
28         long before, after;
29
30         if (false)
31         {
32             intlist = api.getInterfaceList ("");
33             System.out.printf ("Unfiltered interface list:\n%s", intlist);
34             
35             trips = 0;
36             
37             contexts = new int[6];
38             
39             for (i = 0; i < 6; i++)
40             {
41                 contexts[i] = api.swInterfaceSetFlags 
42                     (5 + i /* sw_if_index */,
43                      (byte)1 /* admin_up */,
44                      (byte)1 /* link_up (ignored) */,
45                      (byte)0 /* deleted */);
46             }
47             
48             /* Thread.sleep (1); */
49             errors = 0;
50             saved_error = 0;
51             
52             for (i = 0; i < 6; i ++)
53             {
54                 while (true)
55                 {
56                     rv = api.getRetval (contexts[i], 1 /* release */);
57                     if (rv != -77)
58                         break;
59                     Thread.sleep (1);
60                     trips++;
61                 }
62                 if (rv < 0)
63                 {
64                     saved_error = rv;
65                     errors++;
66                 }
67             }
68             
69             if (errors == 0)
70                 System.out.printf ("intfcs up...\n");
71             else
72                 System.out.printf 
73                     ("%d errors, last error %d...\n", errors, saved_error);
74         }
75         
76         limit = 250000;
77         saved_error = 0;
78         errors = 0;
79         contexts = new int [limit];
80         byte [] address = new byte [4];
81         byte [] zeros = new byte [4];
82
83         address[0] = (byte)192;
84         address[1] = (byte)168;
85         address[2] = (byte)2;
86         address[3] = (byte)1;
87
88         for (i = 0; i < 4; i++)
89             zeros[i] = 0;
90
91         System.out.printf ("start %d route ops ...", limit);
92
93         before = System.currentTimeMillis();
94
95         for (i = 0; i < limit; i++) {
96             contexts[i] = api.ipAddDelRoute 
97                 (0 /* int nextHopSwIfIndex */, 
98                  0 /* int vrfId */, 
99                  0 /* int lookupInVrf */, 
100                  0 /* int resolveAttempts */, 
101                  0 /* int classifyTableIndex */, 
102                  (byte)0 /* byte createVrfIfNeeded */, 
103                  (byte)0 /* byte resolveIfNeeded */, 
104                  (byte)1 /* byte isAdd */, 
105                  (byte)1 /* byte isDrop */, 
106                  (byte)0 /* byte isIpv6 */, 
107                  (byte)0 /* byte isLocal */, 
108                  (byte)0 /* byte isClassify */, 
109                  (byte)0 /* byte isMultipath */, 
110                  (byte)0 /* byte notLast */, 
111                  (byte)0 /* byte nextHopWeight */, 
112                  (byte)32 /* byte dstAddressLength */, 
113                  address, 
114                  zeros);
115             
116             address[3] += 1;
117             if (address[3] == 0)
118             {
119                 address[2] += 1;
120                 if (address[2] == 0)
121                 {
122                     address[1] += 1;
123                     {
124                         if (address[1] == 0)
125                         {
126                             address[0] += 1;
127                         }
128                     }
129                 }
130             }
131         }
132
133         trips = 0;
134                         
135         for (i = 0; i < limit; i++)
136         {
137             while (true)
138             {
139                 rv = api.getRetval (contexts[i], 1 /* release */);
140                 if (rv != -77)
141                     break;
142                 Thread.sleep (1);
143                 trips++;
144             }
145             if (rv < 0)
146             {
147                 saved_error = rv;
148                 errors++;
149             }
150         }
151
152         after = System.currentTimeMillis();
153
154
155         if (errors == 0)
156             System.out.printf ("done %d route ops (all OK)...\n", limit);
157         else
158             System.out.printf 
159                 ("%d errors, last error %d...\n", errors, saved_error);
160         
161         System.out.printf ("result in %d trips\n", trips);
162
163         System.out.printf ("%d routes in %d milliseconds, %d routes/msec\n",
164                            limit, after - before, 
165                            limit / (after - before));
166
167         api.close();
168         System.out.printf ("Done...\n");
169     }
170 }