ca01f18d71da0c289411eb7d0a7a6447b253f41e
[vpp.git] / vpp-api / lua / examples / example-acl-plugin.lua
1 --[[
2 /*
3  * 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:
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
18
19 vpp = require "vpp-lapi"
20
21 root_dir = "/home/ubuntu/vpp"
22 pneum_path = root_dir .. "/build-root/install-vpp_debug-native/vpp-api/lib64/libpneum.so"
23
24 vpp:init({ pneum_path = pneum_path })
25
26 vpp:consume_api(root_dir .. "/build-root/install-vpp_debug-native/vlib-api/vlibmemory/memclnt.api")
27 vpp:consume_api(root_dir .. "/build-root/install-vpp_debug-native/vpp/vpp-api/vpe.api")
28 vpp:connect("aytest")
29 vpp:consume_api(root_dir .. "/plugins/acl-plugin/acl/acl.api", "acl")
30
31 -- api calls
32 reply = vpp:api_call("show_version")
33 print("Version: ", reply[1].version)
34 print(vpp.hex_dump(reply[1].version))
35 print(vpp.dump(reply))
36 print("---")
37
38 reply = vpp:api_call("acl_del", { context = 42, acl_index = 230 })
39 print(vpp.dump(reply))
40 print("---")
41
42 reply = vpp:api_call("acl_del", { context = 42, acl_index = 8 })
43 print(vpp.dump(reply))
44 print("---")
45
46 reply = vpp:api_call("acl_del", { context = 42, acl_index = 15 })
47 print(vpp.dump(reply))
48 print("---")
49
50 reply = vpp:api_call("acl_add", { context = 42, count = 2, r = { { is_permit = 1, is_ipv6 = 1 }, { is_permit = 0, is_ipv6 = 1 } } })
51 print(vpp.dump(reply))
52 print("---")
53 interface_acl_in = reply[1].acl_index
54
55 reply = vpp:api_call("acl_add", { context = 42, count = 3, r = { { is_permit = 1, is_ipv6 = 1 }, { is_permit = 0, is_ipv6 = 1 }, { is_permit = 1, is_ipv6 = 0 } } })
56 print(vpp.dump(reply))
57 print("---")
58 interface_acl_out = reply[1].acl_index
59
60
61 reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 1, acl_index = interface_acl_in })
62 print(vpp.dump(reply))
63 print("---")
64 reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 1, acl_index = interface_acl_in })
65 print(vpp.dump(reply))
66 print("---")
67
68 reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 0, acl_index = interface_acl_out })
69 print(vpp.dump(reply))
70 print("---")
71 reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 0, acl_index = interface_acl_out })
72 print(vpp.dump(reply))
73 print("---")
74
75 reply = vpp:api_call("acl_add", { context = 42, count = 0 })
76 print(vpp.dump(reply))
77 print("---")
78
79 acl_index_to_delete = reply[1].acl_index
80 print("Deleting " .. tostring(acl_index_to_delete))
81 reply = vpp:api_call("acl_del", { context = 42, acl_index = acl_index_to_delete })
82 print(vpp.dump(reply))
83 print("---")
84
85 reply = vpp:api_call("acl_dump", { context = 42, sw_if_index = 0})
86 for ri, rv in ipairs(reply) do 
87   print("Reply message #" .. tostring(ri))
88   print(vpp.dump(rv))
89   for ai, av in ipairs(rv.r) do
90     print("ACL rule #" .. tostring(ai) .. " : " .. vpp.dump(av))
91   end
92    
93 end
94 print("---")
95
96 reply = vpp:api_call("acl_del", { context = 42, acl_index = interface_acl_out })
97 print(vpp.dump(reply))
98 print("---")
99 reply = vpp:api_call("acl_del", { context = 42, acl_index = interface_acl_in })
100 print(vpp.dump(reply))
101 print("---")
102
103 reply = vpp:api_call("acl_dump", { context = 42, sw_if_index = 0})
104 print(vpp.dump(reply))
105 print("---")
106
107
108 vpp:disconnect()
109
110