# Set enabled traces
traces = testbed_instance._get_traces(guid)
- element.capture = 'packets' in traces
+ for capmode in ('pcap', 'packets'):
+ if capmode in traces:
+ element.capture = capmode
+ break
+ else:
+ element.capture = False
# Do some validations
element.validate()
"name": "packets",
"help": "Detailled log of all packets going through the interface",
}),
+ "pcap": dict({
+ "name": "pcap",
+ "help": "PCAP trace of all packets going through the interface",
+ }),
})
create_order = [ INTERNET, NODE, NODEIFACE, TAPIFACE, TUNIFACE, NETPIPE, NEPIDEPENDENCY, NS3DEPENDENCY, DEPENDENCY, APPLICATION ]
"txqueuelen",
"tun_proto", "tun_addr", "tun_port", "tun_key"
],
- "traces": ["packets"],
+ "traces": ["packets", "pcap"],
"connector_types": ["node","udp","tcp","fd->"],
"tags": [tags.INTERFACE, tags.ALLOW_ADDRESSES],
}),
"txqueuelen",
"tun_proto", "tun_addr", "tun_port", "tun_key"
],
- "traces": ["packets"],
+ "traces": ["packets", "pcap"],
"connector_types": ["node","udp","tcp","fd->"],
"tags": [tags.INTERFACE, tags.ALLOW_ADDRESSES],
}),
"-N", "--no-capture", dest="no_capture",
action = "store_true",
default = False,
- help = "If specified, packets won't be logged to standard error "
- "(default is to log them to standard error). " )
+ help = "If specified, packets won't be logged to standard output "
+ "(default is to log them to standard output). " )
+parser.add_option(
+ "-c", "--pcap-capture", dest="pcap_capture", metavar="FILE",
+ default = None,
+ help = "If specified, packets won't be logged to standard output, "
+ "but dumped to a pcap-formatted trace in the specified file. " )
(options, remaining_args) = parser.parse_args(sys.argv[1:])
cipher_key = options.cipher_key,
udp = options.udp,
TERMINATE = TERMINATE,
- stderr = open("/dev/null","w") if options.no_capture
- else sys.stderr
+ stderr = open("/dev/null","w")
)
sock.connect(options.pass_fd)
passfd.sendfd(sock, tun.fileno(), '0')
- # Launch a tcpdump subprocess, to capture and dump packets,
- # we will not be able to capture them ourselves.
- # Make sure to catch sigterm and kill the tcpdump as well
- tcpdump = subprocess.Popen(
- ["tcpdump","-l","-n","-i",tun_name])
-
# just wait forever
def tun_fwd(tun, remote):
while not TERMINATE:
rsock,raddr = lsock.accept()
remote = os.fdopen(rsock.fileno(), 'r+b', 0)
+ if not options.no_capture:
+ # Launch a tcpdump subprocess, to capture and dump packets.
+ # Make sure to catch sigterm and kill the tcpdump as well
+ tcpdump = subprocess.Popen(
+ ["tcpdump","-l","-n","-i",tun_name, "-s", "4096"]
+ + ["-w",options.pcap_capture,"-U"] * bool(options.pcap_capture) )
+
print >>sys.stderr, "Connected"
tun_fwd(tun, remote)
args.extend(("-Q",str(local_txq)))
if not local_cap:
args.append("-N")
+ elif local_cap == 'pcap':
+ args.extend(('-c','pcap'))
if extra_args:
args.extend(map(str,extra_args))
if not listen and check_proto != 'fd':
time.sleep(interval)
interval = min(30.0, interval * 1.1)
+ _TRACEMAP = {
+ # tracename : (remotename, localname)
+ 'packets' : ('capture','capture'),
+ 'pcap' : ('pcap','capture.pcap'),
+ }
+
def remote_trace_path(self, whichtrace):
- if whichtrace != 'packets':
+ tracemap = self._TRACEMAP
+
+ if whichtrace not in tracemap:
return None
- return os.path.join(self.home_path, 'capture')
+ return os.path.join(self.home_path, tracemap[whichtrace][1])
def sync_trace(self, local_dir, whichtrace):
- if whichtrace != 'packets':
+ tracemap = self._TRACEMAP
+
+ if whichtrace not in tracemap:
return None
local = self.local()
if not local:
return None
- local_path = os.path.join(local_dir, 'capture')
+ local_path = os.path.join(local_dir, tracemap[whichtrace][1])
# create parent local folders
if os.path.dirname(local_path):
# sync files
(out,err),proc = server.popen_scp(
'%s@%s:%s' % (local.node.slicename, local.node.hostname,
- os.path.join(self.home_path, 'capture')),
+ os.path.join(self.home_path, tracemap[whichtrace][0])),
local_path,
port = None,
agent = None,