summaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/tests/test_cli.py
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2018-06-12 21:06:44 +0200
committerFlorin Coras <florin.coras@gmail.com>2018-06-22 03:00:45 +0000
commita7564e8004fd6d9a63eb0605f752f27a71403645 (patch)
tree15a97b1b7852dfbdee28c56e0d58218689126c1b /src/vpp-api/python/tests/test_cli.py
parentd600ffe13a0f8f5d11fdea6ab7b24a364c968347 (diff)
Python API: Add enum and union support.
As well as a rewrite of the encoders/decoders to make it more readable and extensible. (Re-commit after fix to verify build.) Change-Id: Ic244d3cebe070bb2570491f8a24f4a1e203f889a Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vpp-api/python/tests/test_cli.py')
-rwxr-xr-xsrc/vpp-api/python/tests/test_cli.py52
1 files changed, 0 insertions, 52 deletions
diff --git a/src/vpp-api/python/tests/test_cli.py b/src/vpp-api/python/tests/test_cli.py
deleted file mode 100755
index 66fb6943e70..00000000000
--- a/src/vpp-api/python/tests/test_cli.py
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/usr/bin/env python
-
-from __future__ import print_function
-import unittest, sys, time, threading, struct
-import test_base
-import vpp_papi
-from ipaddress import *
-
-import glob, subprocess
-class TestPAPI(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
- #
- # Start main VPP process
- cls.vpp_bin = glob.glob(test_base.scriptdir+'/../../../build-root/install-vpp*-native/vpp/bin/vpp')[0]
- print("VPP BIN:", cls.vpp_bin)
- cls.vpp = subprocess.Popen([cls.vpp_bin, "unix", "nodaemon"], stderr=subprocess.PIPE)
- print('Started VPP')
- # For some reason unless we let VPP start up the API cannot connect.
- time.sleep(0.3)
- @classmethod
- def tearDownClass(cls):
- cls.vpp.terminate()
-
- def setUp(self):
- print("Connecting API")
- r = vpp_papi.connect("test_papi")
- self.assertEqual(r, 0)
-
- def tearDown(self):
- r = vpp_papi.disconnect()
- self.assertEqual(r, 0)
-
- #
- # The tests themselves
- #
-
- #
- # Basic request / reply
- #
- def test_cli_request(self):
- print(vpp_papi.cli_exec('show version verbose'))
- #t = vpp_papi.cli_inband_request(len(cmd), cmd)
- #print('T:',t)
- #reply = t.reply[0].decode().rstrip('\x00')
- #print(reply)
- #program = t.program.decode().rstrip('\x00')
- #self.assertEqual('vpe', program)
-
-
-if __name__ == '__main__':
- unittest.main()
2' href='#n252'>252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
/*
 * Copyright (c) 2017 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.
 */

#ifndef __VOM_INTERFACE_CMDS_H__
#define __VOM_INTERFACE_CMDS_H__

#include <vapi/vapi.hpp>

#include "vom/dump_cmd.hpp"
#include "vom/event_cmd.hpp"
#include "vom/interface.hpp"
#include "vom/rpc_cmd.hpp"

#include <vapi/af_packet.api.vapi.hpp>
#include <vapi/interface.api.vapi.hpp>
#include <vapi/stats.api.vapi.hpp>
#include <vapi/tap.api.vapi.hpp>
#include <vapi/vpe.api.vapi.hpp>

namespace VOM {

namespace interface_cmds {
/**
 * Factory method to construct a new interface from the VPP record
 */
std::unique_ptr<interface> new_interface(
  const vapi_payload_sw_interface_details& vd);

/**
 * A command class to create Loopback interfaces in VPP
 */
class loopback_create_cmd : public interface::create_cmd<vapi::Create_loopback>
{
public:
  /**
   * Constructor taking the HW::item to update
   * and the name of the interface to create
   */
  loopback_create_cmd(HW::item<handle_t>& item, const std::string& name);
  ~loopback_create_cmd() = default;

  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);

  /**
 * convert to string format for debug purposes
 */
  std::string to_string() const;
};

/**
 * A command class to create af_packet interfaces in VPP
 */
class af_packet_create_cmd
  : public interface::create_cmd<vapi::Af_packet_create>
{
public:
  /**
   * Constructor taking the HW::item to update
   * and the name of the interface to create
   */
  af_packet_create_cmd(HW::item<handle_t>& item, const std::string& name);
  ~af_packet_create_cmd() = default;
  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);
  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;
};

/**
* A command class to create TAP interfaces in VPP
*/
class tap_create_cmd : public interface::create_cmd<vapi::Tap_connect>
{
public:
  /**
   * Constructor taking the HW::item to update
   * and the name of the interface to create
   */
  tap_create_cmd(HW::item<handle_t>& item, const std::string& name);
  ~tap_create_cmd() = default;

  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);

  /**
 * convert to string format for debug purposes
 */
  std::string to_string() const;
};

/**
 * A command class to delete loopback interfaces in VPP
 */
class loopback_delete_cmd : public interface::delete_cmd<vapi::Delete_loopback>
{
public:
  /**
   * Constructor taking the HW::item to update
   */
  loopback_delete_cmd(HW::item<handle_t>& item);

  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);
  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;
};

/**
 * A command class to delete af-packet interfaces in VPP
 */
class af_packet_delete_cmd
  : public interface::delete_cmd<vapi::Af_packet_delete>
{
public:
  /**
   * Constructor taking the HW::item to update
   * and the name of the interface to delete
   */
  af_packet_delete_cmd(HW::item<handle_t>& item, const std::string& name);

  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);
  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;
};

/**
* A command class to delete TAP interfaces in VPP
*/
class tap_delete_cmd : public interface::delete_cmd<vapi::Tap_delete>
{
public:
  /**
   * Constructor taking the HW::item to update
   */
  tap_delete_cmd(HW::item<handle_t>& item);

  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);
  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;
};

/**
 * A command class to set tag on interfaces
 */
class set_tag
  : public rpc_cmd<HW::item<handle_t>, rc_t, vapi::Sw_interface_tag_add_del>
{
public:
  /**
   * Constructor taking the HW::item to update
   */
  set_tag(HW::item<handle_t>& item, const std::string& name);

  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);

  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;

  /**
   * Comparison operator - only used for UT
   */
  bool operator==(const set_tag& i) const;

private:
  /**
   * The tag to add
   */
  const std::string m_name;
};

/**
 * A cmd class that changes the admin state
 */
class state_change_cmd : public rpc_cmd<HW::item<interface::admin_state_t>,
                                        rc_t,
                                        vapi::Sw_interface_set_flags>
{
public:
  /**
   * Constructor taking the HW::item to update
   * and the name handle of the interface whose state is to change
   */
  state_change_cmd(HW::item<interface::admin_state_t>& s,
                   const HW::item<handle_t>& h);

  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);
  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;

  /**
   * Comparison operator - only used for UT
   */
  bool operator==(const state_change_cmd& i) const;

private:
  /**
   * the handle of the interface to update
   */
  const HW::item<handle_t>& m_hdl;
};

/**
 * A command class that binds an interface to an L3 table
 */
class set_table_cmd : public rpc_cmd<HW::item<route::table_id_t>,
                                     rc_t,
                                     vapi::Sw_interface_set_table>
{
public:
  /**
   * Constructor taking the HW::item to update
   * and the name handle of the interface whose table is to change
   */
  set_table_cmd(HW::item<route::table_id_t>& item,
                const l3_proto_t& proto,
                const HW::item<handle_t>& h);

  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);

  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;

  /**
   * Comparison operator - only used for UT
   */
  bool operator==(const set_table_cmd& i) const;

private:
  /**
   * the handle of the interface to update
   */
  const HW::item<handle_t>& m_hdl;

  /**
   * The L3 protocol of the table
   */
  l3_proto_t m_proto;
};

/**
 * A command class that binds an interface to an L3 table
 */
class set_mac_cmd : public rpc_cmd<HW::item<l2_address_t>,
                                   rc_t,
                                   vapi::Sw_interface_set_mac_address>
{
public:
  /**
   * Constructor taking the HW::item to update
   * and the handle of the interface
   */
  set_mac_cmd(HW::item<l2_address_t>& item, const HW::item<handle_t>& h);

  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);

  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;

  /**
   * Comparison operator - only used for UT
   */
  bool operator==(const set_mac_cmd& i) const;

private:
  /**
   * the handle of the interface to update
   */
  const HW::item<handle_t>& m_hdl;
};

/**
 * A command class represents our desire to recieve interface events
 */
class events_cmd
  : public event_cmd<vapi::Want_interface_events, vapi::Sw_interface_event>
{
public:
  /**
   * Constructor taking the listner to notify
   */
  events_cmd(interface::event_listener& el);

  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);

  /**
   * Retires the command - unsubscribe from the events.
   */
  void retire(connection& con);

  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;

  /**
   * Comparison operator - only used for UT
   */
  bool operator==(const events_cmd& i) const;

  /**
   * Called when it's time to poke the listeners
   */
  void notify();

private:
  /**
   * The listeners to notify when data/events arrive
   */
  interface::interface::event_listener& m_listener;
};

/**
 * A command class represents our desire to recieve interface stats
 */
class stats_cmd : public event_cmd<vapi::Want_per_interface_combined_stats,
                                   vapi::Vnet_per_interface_combined_counters>
{
public:
  /**
   * Constructor taking the listner to notify
   */
  stats_cmd(interface::stat_listener& el,
            const std::vector<handle_t>& interfaces);

  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);

  /**
   * Retires the command - unsubscribe from the stats.
   */
  void retire(connection& con);

  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;

  /**
   * Comparison operator - only used for UT
   */
  bool operator==(const stats_cmd& i) const;

  /**
   * Called when it's time to poke the listeners
   */
  void notify();

private:
  /**
   * The listeners to notify when data/stats arrive
   */
  interface::interface::stat_listener& m_listener;

  std::vector<handle_t> m_swifindex;
};

/**
 * A cmd class that Dumps all the Vpp interfaces
 */
class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_dump>
{
public:
  /**
   * Default Constructor
   */
  dump_cmd();

  /**
   * Issue the command to VPP/HW
   */
  rc_t issue(connection& con);
  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;

  /**
   * Comparison operator - only used for UT
   */
  bool operator==(const dump_cmd& i) const;
};
};
};
/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "mozilla")
 * End:
 */
#endif