blob: 936ce9df202c6a60b4e6a3ed5d3c3e8e63188be8 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
2'''
3Created on 12-Feb-2013
4
5@author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
6
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20
21
22FlowVisorCliDriver is the basic driver which will handle the Mininet functions
23'''
24
25import pexpect
26import struct
27import fcntl
28import os
29import signal
30import re
31import sys
32import time
33
34sys.path.append("../")
35
36from drivers.common.cli.remotetestbeddriver import RemoteTestBedDriver
37
38class FlowVisorCliDriver(RemoteTestBedDriver):
39 '''
40 FlowVisorCliDriver is the basic driver which will handle the Mininet functions
41 '''
42 def __init__(self):
43 super(RemoteTestBedDriver, self).__init__()
44
45 def connect(self,**connectargs):
46 for key in connectargs:
47 vars(self)[key] = connectargs[key]
48
49 self.name = self.options['name']
50
51 self.handle = super(FlowVisorCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
52 if self.handle :
53 main.log.info(self.name+" connected successfully")
54 return self.handle
55 else :
56 main.log.error("Failed to connect "+self.name)
57 return main.FALSE
58
59 def removeFlowSpace(self,id):
60 if id == "all":
61 flow_space = self.listFlowSpace()
62 flow_ids = re.findall("\,id=\[(\d+)\]", flow_space)
63 for id in flow_ids :
64 self.removeFlowSpace(id)
65 else :
66 self.execute(cmd="clear",prompt="\$",timeout=10)
67 self.execute(cmd="fvctl removeFlowSpace "+id,prompt="passwd:",timeout=10)
68 self.execute(cmd="\r",prompt="\$",timeout=10)
69 main.log.info("Removed flowSpace which is having id :"+id)
70
71 return main.TRUE
72
73 def addFlowSpace(self,flow_space):
74 self.execute(cmd="clear",prompt="\$",timeout=10)
75 self.execute(cmd="fvctl addFlowSpace "+flow_space,prompt="passwd:",timeout=10)
76 self.execute(cmd="\r",prompt="\$",timeout=10)
77 sucess_match = re.search("success\:\s+(\d+)", main.last_response)
78 if sucess_match :
79 main.log.info("Added flow Space and id is "+sucess_match.group(1))
80 return main.TRUE
81 else :
82 return main.FALSE
83
84 def listFlowSpace(self):
85 self.execute(cmd="clear",prompt="\$",timeout=10)
86 self.execute(cmd="fvctl listFlowSpace ",prompt="passwd:",timeout=10)
87 self.execute(cmd="\r",prompt="\$",timeout=10)
88 flow_space = main.last_response
89 flow_space = self.remove_contol_chars( flow_space)
90 flow_space = re.sub("rule\s(\d+)\:", "\nrule "+r'\1'+":",flow_space)
91 #main.log.info(flow_space)
92
93 return main.TRUE
94
95 def listDevices(self):
96 self.execute(cmd="clear",prompt="\$",timeout=10)
97 self.execute(cmd="fvctl listDevices ",prompt="passwd:",timeout=10)
98 self.execute(cmd="\r",prompt="\$",timeout=10)
99 devices_list = ''
100 last_response = re.findall("(Device\s\d+\:\s((\d|[a-z])(\d|[a-z])\:)+(\d|[a-z])(\d|[a-z]))", main.last_response)
101
102 for resp in last_response :
103 devices_match = re.search("(Device\s\d+\:\s((\d|[a-z])(\d|[a-z])\:)+(\d|[a-z])(\d|[a-z]))", str(resp))
104 if devices_match:
105 devices_list = devices_list+devices_match.group(0)+"\n"
106 main.log.info("List of Devices \n"+devices_list)
107 return main.TRUE
108
109
110