--[[ /* * Copyright (c) 2016 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. */ ]] -- Experimental prototype CLI using API to VPP, with tab completion -- -- Written by Andrew Yourtchenko (ayourtch@cisco.com) 2010,2016 -- vpp = require "vpp-lapi" local dotdotdot = "..." -- First the "readline" routine readln = { split = function(str, pat) local t = {} -- NOTE: use {n = 0} in Lua-5.0 local fpat = "(.-)" .. pat local last_end = 1 if str then local s, e, cap = str:find(fpat, 1) while s do if s ~= 1 or cap ~= "" then table.insert(t,cap) end last_end = e+1 s, e, cap = str:find(fpat, last_end) end if last_end <= #str then cap = str:sub(last_end) table.insert(t, cap) end end return t end, reader = function() local rl = {} rl.init = function() os.execute("stty -icanon min 1 -echo") rl.rawmode = true end rl.done = function() os.execute("stty icanon echo") rl.rawmode = false end rl.prompt = ">" rl.history = { "" } rl.history_index = 1 rl.history_length = 1 rl.hide_cmd = function() local bs = string.char(8) .. " " .. string.char(8) for i = 1, #rl.command do io.stdout:write(bs) end end rl.show_cmd = function() if rl.command then io.stdout:write(rl.command) end end rl.store_history = function(cmd) if cmd == "" then return end rl.history[rl.history_length] = cmd rl.history_length = rl.history_length + 1 rl.history_index = rl.history_length rl.history[rl.history_length] = "" end rl.readln = function() local done = false local need_prompt = true rl.command = "" if not rl.rawmode then rl.init() end while not done do if need_prompt then io.stdout:write(rl.prompt) io.stdout:write(rl.command) need_prompt = false end local ch = io.stdin:read(1) if ch:byte(1) == 27 then -- CONTROL local ch2 = io.stdin:read(1) -- arrows if ch2:byte(1) == 91 then local ch3 = io.stdin:read(1) local b = ch3:byte(1) if b == 65 then ch = "UP" elseif b == 66 then ch = "DOWN" elseif b == 67 then ch = "RIGHT" elseif b == 68 then ch = "LEFT" end -- print("Byte: " .. ch3:byte(1)) -- if ch3:byte(1) end end if ch == "?" then io.stdout:write(ch) io.stdout:write("\n") if rl.help then rl.help(rl) end need_prompt = true elseif ch == "\t" then if rl.tab_complete then rl.tab_complete(rl) end io.stdout:write("\n") need_prompt = true elseif ch == "\n" then io.stdout:write(ch) done = true elseif ch == "\004" then io.stdout:write("\n") rl.command = nil done = true elseif ch == string.char(127) then if rl.command ~= "" then io.stdout:write(string.char(8) .. " " .. string.char(8)) rl.command = string.sub(rl.command, 1, -2) end elseif #ch > 1 then -- control char if ch == "UP" then rl.hide_cmd() if rl.history_index == #rl.history then rl.history[rl.history_index] = rl.command end if rl.history_index > 1 then rl.history_index = rl.history_index - 1 rl.command = rl.history[rl.history_index] end rl.show_cmd() elseif ch == "DOWN" then rl.hide_cmd() if rl.history_index < rl.history_length then rl.history_index = rl.history_index + 1 rl.command = rl.history[rl.history_index] end rl.show_cmd() end else io.stdout:write(ch) rl.command = rl.command .. ch end end if rl.command then rl.store_history(rl.command) end return rl.command end return rl end } --[[ r = reader() local done = false while not done do local cmd = r.readln() print("Command: " .. tostring(cmd)) if not cmd or cmd == "quit" then done = true end end r.done() ]] --------- MDS show tech parser local print_section = nil local list_sections = false local curr_section = "---" local curr_parser = nil -- by default operate in batch mode local batch_mode = true local db = {} local device = {} device.output = {} local seen_section = {} function start_collection(name) device = {} seen_section = {} end function print_error(errmsg) print("@#$:" .. errmsg) end function keys(tbl) local t = {} for k, v in pairs(tbl) do table.insert(t, k) end return t end function tset (parent, ...) -- print ('set', ...) local len = select ('#', ...) local key, value = select (len-1, ...)
from __future__ import print_function
import unittest
import vpp_papi
import pot, snat
print('Plugins:')
vpp_papi.plugin_show()
r = vpp_papi.connect('ole')
r = vpp_papi.show_version()
print('R:', r)
r = snat.snat_interface_add_del_feature(1, 1, 1)
print('R:', r)
list_name = 'foobar'
r = pot.pot_profile_add(0, 1, 123, 123, 0, 12, 0, 23, len(list_name), list_name)
print('R:', r)
vpp_papi.disconnect()