aboutsummaryrefslogtreecommitdiffstats
path: root/vpp-japi/japi/test/demo.java
blob: ef419d70658b44a6ebbf8737e41cbfb9460c0061 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.openvpp.vppjapi.*;

public class demo extends vppApi {
    public static void main (String[] args) throws Exception {
        vppApi api = new vppApi ();
        String intlist;
        int [] contexts;
        int i, limit;
        int trips;
        int rv, errors, saved_error;
        long before, after;

        rv = api.clientConnect ("JavaTest");
        if (rv == 0)
            System.out.printf ("Connected OK...");
        else
        {
            System.out.printf ("clientConnect returned %d\n", rv);
            System.exit (1);
        }

        if (false)
        {
            intlist = api.getInterfaceList ("");
            System.out.printf ("Unfiltered interface list:\n%s", intlist);
            
            trips = 0;
            
            contexts = new int[6];
            
            for (i = 0; i < 6; i++)
            {
                contexts[i] = api.swInterfaceSetFlags 
                    (5 + i /* sw_if_index */,
                     (byte)1 /* admin_up */,
                     (byte)1 /* link_up (ignored) */,
                     (byte)0 /* deleted */);
            }
            
            /* Thread.sleep (1); */
            errors = 0;
            saved_error = 0;
            
            for (i = 0; i < 6; i ++)
            {
                while (true)
                {
                    rv = api.getRetval (contexts[i], 1 /* release */);
                    if (rv != -77)
                        break;
                    Thread.sleep (1);
                    trips++;
                }
                if (rv < 0)
                {
                    saved_error = rv;
                    errors++;
                }
            }
            
            if (errors == 0)
                System.out.printf ("intfcs up...\n");
            else
                System.out.printf 
                    ("%d errors, last error %d...\n", errors, saved_error);
        }
        
        limit = 250000;
        saved_error = 0;
        errors = 0;
        contexts = new int [limit];
        byte [] address = new byte [4];
        byte [] zeros = new byte [4];

        address[0] = (byte)192;
        address[1] = (byte)168;
        address[2] = (byte)2;
        address[3] = (byte)1;

        for (i = 0; i < 4; i++)
            zeros[i] = 0;

        System.out.printf ("start %d route ops ...", limit);

        before = System.currentTimeMillis();

        for (i = 0; i < limit; i++) {
            contexts[i] = api.ipAddDelRoute 
                (0 /* int nextHopSwIfIndex */, 
                 0 /* int vrfId */, 
                 0 /* int lookupInVrf */, 
                 0 /* int resolveAttempts */, 
                 0 /* int classifyTableIndex */, 
                 (byte)0 /* byte createVrfIfNeeded */, 
                 (byte)0 /* byte resolveIfNeeded */, 
                 (byte)1 /* byte isAdd */, 
                 (byte)1 /* byte isDrop */, 
                 (byte)0 /* byte isIpv6 */, 
                 (byte)0 /* byte isLocal */, 
                 (byte)0 /* byte isClassify */, 
                 (byte)0 /* byte isMultipath */, 
                 (byte)0 /* byte notLast */, 
                 (byte)0 /* byte nextHopWeight */, 
                 (byte)32 /* byte dstAddressLength */, 
                 address, 
                 zeros);
            
            address[3] += 1;
            if (address[3] == 0)
            {
                address[2] += 1;
                if (address[2] == 0)
                {
                    address[1] += 1;
                    {
                        if (address[1] == 0)
                        {
                            address[0] += 1;
                        }
                    }
                }
            }
        }

        trips = 0;
                        
        for (i = 0; i < limit; i++)
        {
            while (true)
            {
                rv = api.getRetval (contexts[i], 1 /* release */);
                if (rv != -77)
                    break;
                Thread.sleep (1);
                trips++;
            }
            if (rv < 0)
            {
                saved_error = rv;
                errors++;
            }
        }

        after = System.currentTimeMillis();


        if (errors == 0)
            System.out.printf ("done %d route ops (all OK)...\n", limit);
        else
            System.out.printf 
                ("%d errors, last error %d...\n", errors, saved_error);
        
        System.out.printf ("result in %d trips\n", trips);

        System.out.printf ("%d routes in %d milliseconds, %d routes/msec\n",
                           limit, after - before, 
                           limit / (after - before));

        api.clientDisconnect();
        System.out.printf ("Done...\n");
    }
}