Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topotato: Assert Ping #133

Open
wants to merge 2 commits into
base: topotato-base
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions topotato/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
from typing_extensions import Literal # type: ignore

from scapy.packet import Packet # type: ignore
from scapy.all import IP, ICMP # type: ignore
import pytest

from .utils import json_cmp, text_rich_cmp, deindent
from .base import TopotatoItem, TopotatoFunction, skiptrace
from .livescapy import TimedScapy
from .frr.livelog import LogMessage
from .timeline import TimingParams
from .toponom import Router
from .exceptions import (
TopotatoCLICompareFail,
TopotatoCLIUnsuccessfulFail,
Expand Down Expand Up @@ -407,6 +409,55 @@ def __call__(self):
)


class AssertPing(AssertPacket):
_rtr: Router
_iface: str
_iface: str
_other_rtr: Router

@classmethod
def from_parent(cls, parent, name, rtr, iface, other_rtr):
self = super().from_parent(
parent, name="%s:%s/scapy[%s/ping/%s]" % (name, rtr.name, iface, other_rtr)
)

self._rtr = rtr
self._iface = iface
self._other_rtr = other_rtr

rtr_ip = self._rtr.iface_to(self._iface).ip4[0].ip
other_rtr_ip = self._other_rtr.iface_to(self._iface).ip4[0].ip


def expect_pkt(ip: IP, icmp: ICMP):
return ip.src == rtr_ip and ip.dst == other_rtr_ip

self._expect_pkt = expect_pkt

def __call__(self):
if scapy_exc:
pytest.skip(scapy_exc)

router = self.instance.routers[self._rtr.name]

rtr_ip = self._rtr.iface_to(self._iface).ip4[0].ip
other_rtr_ip = self._other_rtr.iface_to(self._iface).ip4[0].ip
eznix86 marked this conversation as resolved.
Show resolved Hide resolved

with router:
sock = NetnsL2Socket(iface=self._iface, promisc=False)
sock.send(
IP(
src=rtr_ip,
dst=other_rtr_ip,
)
/ ICMP(seq=1234)
)

sock.close()

super().__call__()


class AssertLog(TopotatoAssertion, TimedMixin):
# pylint does not understand that from_parent is our __init__
_rtr: str
Expand Down