Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame^] | 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 extends vppApi { |
| 19 | public static void main (String[] args) throws Exception { |
| 20 | vppApi api = new vppApi (); |
| 21 | String intlist; |
| 22 | int [] contexts; |
| 23 | int i, limit; |
| 24 | int trips; |
| 25 | int rv, errors, saved_error; |
| 26 | long before, after; |
| 27 | |
| 28 | rv = api.clientConnect ("JavaTest"); |
| 29 | if (rv == 0) |
| 30 | System.out.printf ("Connected OK..."); |
| 31 | else |
| 32 | { |
| 33 | System.out.printf ("clientConnect returned %d\n", rv); |
| 34 | System.exit (1); |
| 35 | } |
| 36 | |
| 37 | if (false) |
| 38 | { |
| 39 | intlist = api.getInterfaceList (""); |
| 40 | System.out.printf ("Unfiltered interface list:\n%s", intlist); |
| 41 | |
| 42 | trips = 0; |
| 43 | |
| 44 | contexts = new int[6]; |
| 45 | |
| 46 | for (i = 0; i < 6; i++) |
| 47 | { |
| 48 | contexts[i] = api.swInterfaceSetFlags |
| 49 | (5 + i /* sw_if_index */, |
| 50 | (byte)1 /* admin_up */, |
| 51 | (byte)1 /* link_up (ignored) */, |
| 52 | (byte)0 /* deleted */); |
| 53 | } |
| 54 | |
| 55 | /* Thread.sleep (1); */ |
| 56 | errors = 0; |
| 57 | saved_error = 0; |
| 58 | |
| 59 | for (i = 0; i < 6; i ++) |
| 60 | { |
| 61 | while (true) |
| 62 | { |
| 63 | rv = api.getRetval (contexts[i], 1 /* release */); |
| 64 | if (rv != -77) |
| 65 | break; |
| 66 | Thread.sleep (1); |
| 67 | trips++; |
| 68 | } |
| 69 | if (rv < 0) |
| 70 | { |
| 71 | saved_error = rv; |
| 72 | errors++; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | if (errors == 0) |
| 77 | System.out.printf ("intfcs up...\n"); |
| 78 | else |
| 79 | System.out.printf |
| 80 | ("%d errors, last error %d...\n", errors, saved_error); |
| 81 | } |
| 82 | |
| 83 | limit = 250000; |
| 84 | saved_error = 0; |
| 85 | errors = 0; |
| 86 | contexts = new int [limit]; |
| 87 | byte [] address = new byte [4]; |
| 88 | byte [] zeros = new byte [4]; |
| 89 | |
| 90 | address[0] = (byte)192; |
| 91 | address[1] = (byte)168; |
| 92 | address[2] = (byte)2; |
| 93 | address[3] = (byte)1; |
| 94 | |
| 95 | for (i = 0; i < 4; i++) |
| 96 | zeros[i] = 0; |
| 97 | |
| 98 | System.out.printf ("start %d route ops ...", limit); |
| 99 | |
| 100 | before = System.currentTimeMillis(); |
| 101 | |
| 102 | for (i = 0; i < limit; i++) { |
| 103 | contexts[i] = api.ipAddDelRoute |
| 104 | (0 /* int nextHopSwIfIndex */, |
| 105 | 0 /* int vrfId */, |
| 106 | 0 /* int lookupInVrf */, |
| 107 | 0 /* int resolveAttempts */, |
| 108 | 0 /* int classifyTableIndex */, |
| 109 | (byte)0 /* byte createVrfIfNeeded */, |
| 110 | (byte)0 /* byte resolveIfNeeded */, |
| 111 | (byte)1 /* byte isAdd */, |
| 112 | (byte)1 /* byte isDrop */, |
| 113 | (byte)0 /* byte isIpv6 */, |
| 114 | (byte)0 /* byte isLocal */, |
| 115 | (byte)0 /* byte isClassify */, |
| 116 | (byte)0 /* byte isMultipath */, |
| 117 | (byte)0 /* byte notLast */, |
| 118 | (byte)0 /* byte nextHopWeight */, |
| 119 | (byte)32 /* byte dstAddressLength */, |
| 120 | address, |
| 121 | zeros); |
| 122 | |
| 123 | address[3] += 1; |
| 124 | if (address[3] == 0) |
| 125 | { |
| 126 | address[2] += 1; |
| 127 | if (address[2] == 0) |
| 128 | { |
| 129 | address[1] += 1; |
| 130 | { |
| 131 | if (address[1] == 0) |
| 132 | { |
| 133 | address[0] += 1; |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | trips = 0; |
| 141 | |
| 142 | for (i = 0; i < limit; i++) |
| 143 | { |
| 144 | while (true) |
| 145 | { |
| 146 | rv = api.getRetval (contexts[i], 1 /* release */); |
| 147 | if (rv != -77) |
| 148 | break; |
| 149 | Thread.sleep (1); |
| 150 | trips++; |
| 151 | } |
| 152 | if (rv < 0) |
| 153 | { |
| 154 | saved_error = rv; |
| 155 | errors++; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | after = System.currentTimeMillis(); |
| 160 | |
| 161 | |
| 162 | if (errors == 0) |
| 163 | System.out.printf ("done %d route ops (all OK)...\n", limit); |
| 164 | else |
| 165 | System.out.printf |
| 166 | ("%d errors, last error %d...\n", errors, saved_error); |
| 167 | |
| 168 | System.out.printf ("result in %d trips\n", trips); |
| 169 | |
| 170 | System.out.printf ("%d routes in %d milliseconds, %d routes/msec\n", |
| 171 | limit, after - before, |
| 172 | limit / (after - before)); |
| 173 | |
| 174 | api.clientDisconnect(); |
| 175 | System.out.printf ("Done...\n"); |
| 176 | } |
| 177 | } |