blob: 0db31e79ba84cce877df814e03f0c1047cd5fc6d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
import pytest
from atf_python.sys.net.tools import ToolsHelper
from atf_python.sys.net.vnet import VnetTestTemplate
sc = None
def filter_f(x):
ip = x.getlayer(sc.IP)
if not ip:
return False
return ip.proto == 112
class TestCarp(VnetTestTemplate):
REQUIRED_MODULES = ["carp"]
TOPOLOGY = {
"vnet1": {"ifaces": ["if1"]},
"if1": {"prefixes4": [("192.0.2.1/24", "192.0.2.2/24")]},
}
def setup_method(self, method):
global sc
if sc is None:
import scapy.all as _sc
sc = _sc
super().setup_method(method)
@classmethod
def check_carp_src_mac(self, pkts):
for p in pkts:
if not filter_f(p):
continue
print("Packet src mac {}".format(p.src))
if p.src != "00:00:5e:00:01:01":
raise
def test_source_mac(self):
"Test carp packets source address"
if1 = self.vnet.iface_alias_map["if1"]
ToolsHelper.print_output(
"ifconfig {} add vhid 1 192.0.2.203/24".format(if1.name)
)
carp_pkts = sc.sniff(iface=if1.name, stop_filter=filter_f, timeout=5)
self.check_carp_src_mac(carp_pkts)
def test_source_mac_vrrp(self):
"Test VRRP packets source address"
if1 = self.vnet.iface_alias_map["if1"]
ToolsHelper.print_output(
"ifconfig {} add vhid 1 carpver 3 192.0.2.203/24".format(if1.name)
)
carp_pkts = sc.sniff(iface=if1.name, stop_filter=filter_f, timeout=5)
self.check_carp_src_mac(carp_pkts)
|