Merge "testpmd_pvp: Adds pkt_fwd to allow pvp topology testing"
[vswitchperf.git] / src / ovs / dpctl.py
1 # Copyright 2016 Intel Corporation.
2 #
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 """Wrapper for an OVS dpctl (``ovs-dpctl``) for managing datapaths.
16
17 """
18
19 import os
20 import logging
21 import string
22
23 from tools import tasks
24 from conf import settings
25
26 _OVS_LOCAL_DATAPATH = 'ovs-system'
27
28 class DPCtl(object):
29     """remove/show datapaths using ``ovs-dpctl``.
30     """
31     def __init__(self, timeout=10):
32         """Initialise logger.
33
34         :param timeout: Timeout to be used for each command
35
36         :returns: None
37         """
38         self.logger = logging.getLogger(__name__)
39         self.timeout = timeout
40
41     # helpers
42
43     def run_dpctl(self, args, check_error=False):
44         """Run ``ovs-dpctl`` with supplied arguments.
45
46         :param args: Arguments to pass to ``ovs-dpctl``
47         :param check_error: Throw exception on error
48
49         :return: None
50         """
51         cmd = ['sudo', settings.getValue('TOOLS')['ovs-dpctl'],
52                '--timeout',
53                str(self.timeout)] + args
54         return tasks.run_task(
55             cmd, self.logger, 'Running ovs-dpctl ..', check_error)
56
57     # datapath management
58
59     def del_dp(self, dp_name=_OVS_LOCAL_DATAPATH):
60         """Delete local datapath (ovs-dpctl).
61
62         :param br_name: Name of bridge
63
64         :return: None
65         """
66         self.logger.debug('delete datapath ' + dp_name)
67         self.run_dpctl(['del-dp', dp_name])
68