updated test_links to avoid running a system command and the need to use iperf/ping

This commit is contained in:
bharnden 2019-09-10 21:33:35 -07:00
parent fb8fc46d0d
commit b4bc9c23a3
10 changed files with 34 additions and 161 deletions

View file

@ -7,6 +7,8 @@ import threading
import time
import pytest
from mock.mock import MagicMock
from core.api.grpc.client import InterfaceHelper
from core.api.grpc.server import CoreGrpcServer
from core.api.tlv.coreapi import CoreConfMessage, CoreEventMessage
@ -17,7 +19,6 @@ from core.emulator.emudata import IpPrefixes
from core.emulator.enumerations import CORE_API_PORT, ConfigTlvs, EventTlvs, EventTypes
from core.nodes import ipaddress
from core.services.coreservices import ServiceManager
from mock.mock import MagicMock
EMANE_SERVICES = "zebra|OSPFv3MDR|IPForward"

View file

@ -1,4 +1,5 @@
import pytest
from core.config import (
ConfigurableManager,
ConfigurableOptions,

View file

@ -8,6 +8,7 @@ import subprocess
import threading
import pytest
from core.emulator.emudata import NodeOptions
from core.emulator.enumerations import MessageFlags, NodeTypes
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility

View file

@ -4,6 +4,7 @@ Unit tests for testing CORE EMANE networks.
import os
import pytest
from conftest import ping
from core.emane.bypass import EmaneBypassModel
from core.emane.commeffect import EmaneCommEffectModel

View file

@ -3,8 +3,8 @@ from builtins import int
from queue import Queue
import grpc
import pytest
from core.api.grpc import core_pb2
from core.api.grpc.client import CoreGrpcClient
from core.config import ConfigShim

View file

@ -6,6 +6,7 @@ import time
import mock
import pytest
from core.api.tlv import coreapi
from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.emulator.enumerations import (

View file

@ -1,4 +1,3 @@
from core import utils
from core.emulator.emudata import LinkOptions
from core.emulator.enumerations import NodeTypes
@ -19,21 +18,6 @@ def create_ptp_network(session, ip_prefixes):
return node_one, node_two
def ping_output(from_node, to_node, ip_prefixes):
address = ip_prefixes.ip4_address(to_node)
output = from_node.check_cmd(["ping", "-i", "0.05", "-c", "3", address])
return output
def iperf(from_node, to_node, ip_prefixes):
# run iperf server, run client, kill iperf server
address = ip_prefixes.ip4_address(to_node)
vcmd, stdin, stdout, stderr = to_node.client.popen(["iperf", "-s", "-u", "-y", "C"])
from_node.cmd(["iperf", "-u", "-t", "5", "-c", address])
to_node.cmd(["killall", "-9", "iperf"])
return stdout.read().decode("utf-8").strip()
class TestLinks:
def test_ptp(self, session, ip_prefixes):
# given
@ -88,36 +72,42 @@ class TestLinks:
def test_link_update(self, session, ip_prefixes):
# given
delay = 50
bandwidth = 5000000
per = 25
dup = 25
jitter = 10
node_one = session.add_node()
node_two = session.add_node(_type=NodeTypes.SWITCH)
interface_one = ip_prefixes.create_interface(node_one)
session.add_link(node_one.id, node_two.id, interface_one)
interface = node_one.netif(interface_one.id)
output = utils.check_cmd(["tc", "qdisc", "show", "dev", interface.localname])
assert "delay" not in output
assert "rate" not in output
assert "loss" not in output
assert "duplicate" not in output
interface_one_data = ip_prefixes.create_interface(node_one)
session.add_link(node_one.id, node_two.id, interface_one_data)
interface_one = node_one.netif(interface_one_data.id)
assert interface_one.getparam("delay") != delay
assert interface_one.getparam("bw") != bandwidth
assert interface_one.getparam("loss") != per
assert interface_one.getparam("duplicate") != dup
assert interface_one.getparam("jitter") != jitter
# when
link_options = LinkOptions()
link_options.delay = 50
link_options.bandwidth = 5000000
link_options.per = 25
link_options.dup = 25
link_options.delay = delay
link_options.bandwidth = bandwidth
link_options.per = per
link_options.dup = dup
link_options.jitter = jitter
session.update_link(
node_one.id,
node_two.id,
interface_one_id=interface_one.id,
interface_one_id=interface_one_data.id,
link_options=link_options,
)
# then
output = utils.check_cmd(["tc", "qdisc", "show", "dev", interface.localname])
assert "delay" in output
assert "rate" in output
assert "loss" in output
assert "duplicate" in output
assert interface_one.getparam("delay") == delay
assert interface_one.getparam("bw") == bandwidth
assert interface_one.getparam("loss") == per
assert interface_one.getparam("duplicate") == dup
assert interface_one.getparam("jitter") == jitter
def test_link_delete(self, session, ip_prefixes):
# given
@ -137,128 +127,3 @@ class TestLinks:
# then
assert not node_one.netif(interface_one.id)
assert not node_two.netif(interface_two.id)
def test_link_bandwidth(self, session, ip_prefixes):
"""
Test ptp node network with modifying link bandwidth.
:param core.emulator.coreemu.EmuSession session: session for test
:param ip_prefixes: generates ip addresses for nodes
"""
# create link network
node_one, node_two = create_ptp_network(session, ip_prefixes)
# output csv index
bandwidth_index = 8
# run iperf, validate normal bandwidth
stdout = iperf(node_one, node_two, ip_prefixes)
assert stdout
value = int(stdout.split(",")[bandwidth_index])
assert 900000 <= value <= 1100000
# change bandwidth in bits per second
link_options = LinkOptions()
link_options.bandwidth = 500000
session.update_link(node_one.id, node_two.id, link_options=link_options)
# run iperf again
stdout = iperf(node_one, node_two, ip_prefixes)
assert stdout
value = int(stdout.split(",")[bandwidth_index])
assert 400000 <= value <= 600000
def test_link_loss(self, session, ip_prefixes):
"""
Test ptp node network with modifying link packet loss.
:param core.emulator.coreemu.EmuSession session: session for test
:param ip_prefixes: generates ip addresses for nodes
"""
# create link network
node_one, node_two = create_ptp_network(session, ip_prefixes)
# output csv index
loss_index = -2
# run iperf, validate normal bandwidth
stdout = iperf(node_one, node_two, ip_prefixes)
assert stdout
value = float(stdout.split(",")[loss_index])
assert 0 <= value <= 0.5
# change bandwidth in bits per second
link_options = LinkOptions()
link_options.per = 50
session.update_link(node_one.id, node_two.id, link_options=link_options)
# run iperf again
stdout = iperf(node_one, node_two, ip_prefixes)
assert stdout
value = float(stdout.split(",")[loss_index])
assert 40 <= value <= 60
def test_link_delay(self, session, ip_prefixes):
"""
Test ptp node network with modifying link packet delay.
:param core.emulator.coreemu.EmuSession session: session for test
:param ip_prefixes: generates ip addresses for nodes
"""
# create link network
node_one, node_two = create_ptp_network(session, ip_prefixes)
# run ping for delay information
stdout = ping_output(node_one, node_two, ip_prefixes)
assert stdout
rtt_line = stdout.split("\n")[-1]
rtt_values = rtt_line.split("=")[1].split("ms")[0].strip()
rtt_avg = float(rtt_values.split("/")[2])
assert 0 <= rtt_avg <= 0.2
# change delay in microseconds
link_options = LinkOptions()
link_options.delay = 1000000
session.update_link(node_one.id, node_two.id, link_options=link_options)
# run ping for delay information again
stdout = ping_output(node_one, node_two, ip_prefixes)
assert stdout
rtt_line = stdout.split("\n")[-1]
rtt_values = rtt_line.split("=")[1].split("ms")[0].strip()
rtt_avg = float(rtt_values.split("/")[2])
assert 1800 <= rtt_avg <= 2200
def test_link_jitter(self, session, ip_prefixes):
"""
Test ptp node network with modifying link packet jitter.
:param core.emulator.coreemu.EmuSession session: session for test
:param ip_prefixes: generates ip addresses for nodes
"""
# create link network
node_one, node_two = create_ptp_network(session, ip_prefixes)
# output csv index
jitter_index = 9
# run iperf
stdout = iperf(node_one, node_two, ip_prefixes)
assert stdout
value = float(stdout.split(",")[jitter_index])
assert -0.5 <= value <= 0.05
# change jitter in microseconds
link_options = LinkOptions()
link_options.jitter = 1000000
session.update_link(node_one.id, node_two.id, link_options=link_options)
# run iperf again
stdout = iperf(node_one, node_two, ip_prefixes)
assert stdout
value = float(stdout.split(",")[jitter_index])
assert 200 <= value <= 500

View file

@ -2,6 +2,7 @@ import os
import time
import pytest
from core import utils
from core.emulator.emudata import NodeOptions
from core.emulator.enumerations import NodeTypes

View file

@ -1,6 +1,7 @@
import os
import pytest
from core.services.coreservices import CoreService, ServiceDependencies, ServiceManager
_PATH = os.path.abspath(os.path.dirname(__file__))

View file

@ -1,6 +1,7 @@
from xml.etree import ElementTree
import pytest
from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.emulator.emudata import LinkOptions, NodeOptions
from core.emulator.enumerations import NodeTypes