Skip to content

Commit

Permalink
fixup! chore(pipelined): blocking of local ipv6 addresses is tested
Browse files Browse the repository at this point in the history
  • Loading branch information
nstng committed Apr 1, 2022
1 parent 0f210f0 commit a354e3e
Showing 1 changed file with 94 additions and 90 deletions.
184 changes: 94 additions & 90 deletions lte/gateway/python/magma/pipelined/tests/test_access_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from magma.pipelined.openflow.registers import Direction
from magma.pipelined.tests.app.flow_query import RyuDirectFlowQuery as FlowQuery
from magma.pipelined.tests.app.packet_builder import (
IPPacketBuilder,
IPPacketBuilder,
IPv6PacketBuilder,
)
from magma.pipelined.tests.app.packet_injector import ScapyPacketInjector
Expand All @@ -49,6 +49,7 @@
)
from ryu.lib.packet import ether_types


class AbstractAccessControlTest(unittest.TestCase):
BRIDGE = 'testing_br'
IFACE = 'testing_br'
Expand Down Expand Up @@ -129,6 +130,7 @@ def _setupSubscribersIpV6(self):
default_ambr_config, self._tbl_num,
)


class AccessControlTestLTE(AbstractAccessControlTest):
INBOUND_TEST_IP = '127.0.0.1'
OUTBOUND_TEST_IP = '127.1.0.1'
Expand All @@ -137,38 +139,38 @@ class AccessControlTestLTE(AbstractAccessControlTest):
@classmethod
def getConfig(cls):
config = {
'setup_type': 'LTE',
'allow_unknown_arps': False,
'bridge_name': cls.BRIDGE,
'bridge_ip_address': cls.BRIDGE_IP,
'nat_iface': 'eth2',
'enodeb_iface': 'eth1',
'qos': {'enable': False},
'access_control': {
'ip_blocklist': [
{
'ip': cls.INBOUND_TEST_IP,
'direction': 'inbound',
},
{
'ip': cls.OUTBOUND_TEST_IP,
'direction': 'outbound',
},
{
'ip': cls.BOTH_DIR_TEST_IP,
},
],
'block_agw_local_ips': False,
},
'clean_restart': True,
}
'setup_type': 'LTE',
'allow_unknown_arps': False,
'bridge_name': cls.BRIDGE,
'bridge_ip_address': cls.BRIDGE_IP,
'nat_iface': 'eth2',
'enodeb_iface': 'eth1',
'qos': {'enable': False},
'access_control': {
'ip_blocklist': [
{
'ip': cls.INBOUND_TEST_IP,
'direction': 'inbound',
},
{
'ip': cls.OUTBOUND_TEST_IP,
'direction': 'outbound',
},
{
'ip': cls.BOTH_DIR_TEST_IP,
},
],
'block_agw_local_ips': False,
},
'clean_restart': True,
}
return config

@classmethod
def getMconfig(cls):
return PipelineD(
allowed_gre_peers=[{'ip': '1.2.3.4/24', 'key': 123}],
)
allowed_gre_peers=[{'ip': '1.2.3.4/24', 'key': 123}],
)

def test_inbound_ip_match(self):
"""
Expand Down Expand Up @@ -390,42 +392,42 @@ class AccessControlTestCWF(AbstractAccessControlTest):
@classmethod
def getConfig(cls):
config = {
'setup_type': 'CWF',
'allow_unknown_arps': False,
'bridge_name': cls.BRIDGE,
'bridge_ip_address': cls.BRIDGE_IP,
'internal_ip_subnet': '192.168.0.0/16',
'nat_iface': 'eth2',
'enodeb_iface': 'eth1',
'enable_queue_pgm': False,
'clean_restart': True,
'access_control': {
'ip_blocklist': [
{
'setup_type': 'CWF',
'allow_unknown_arps': False,
'bridge_name': cls.BRIDGE,
'bridge_ip_address': cls.BRIDGE_IP,
'internal_ip_subnet': '192.168.0.0/16',
'nat_iface': 'eth2',
'enodeb_iface': 'eth1',
'enable_queue_pgm': False,
'clean_restart': True,
'access_control': {
'ip_blocklist': [
{
'ip': cls.INBOUND_TEST_IP,
'direction': 'inbound',
},
{
'ip': cls.OUTBOUND_TEST_IP,
'direction': 'outbound',
},
{
'ip': cls.BOTH_DIR_TEST_IP,
},
],
'block_agw_local_ips': False,
},
}
},
{
'ip': cls.OUTBOUND_TEST_IP,
'direction': 'outbound',
},
{
'ip': cls.BOTH_DIR_TEST_IP,
},
],
'block_agw_local_ips': False,
},
}
return config

@classmethod
def getMconfig(cls):
return PipelineD(
allowed_gre_peers=[
{'ip': '2.2.2.2/24'},
{'ip': '1.2.3.4/24', 'key': 123},
],
)
allowed_gre_peers=[
{'ip': '2.2.2.2/24'},
{'ip': '1.2.3.4/24', 'key': 123},
],
)

def test_gre_peer_rules(self):
"""
Expand All @@ -451,27 +453,27 @@ class AccessControlTestLocalIpBlockLTE(AbstractAccessControlTest):
@classmethod
def getConfig(cls):
config = {
'setup_type': 'LTE',
'allow_unknown_arps': False,
'bridge_name': cls.BRIDGE,
'bridge_ip_address': cls.BRIDGE_IP,
'nat_iface': 'eth2',
'enodeb_iface': 'eth1',
'qos': {'enable': False},
'access_control': {
'ip_blocklist': [],
'block_agw_local_ips': True,
},
'clean_restart': True,
'mtr_interface': 'mtr0',
}
'setup_type': 'LTE',
'allow_unknown_arps': False,
'bridge_name': cls.BRIDGE,
'bridge_ip_address': cls.BRIDGE_IP,
'nat_iface': 'eth2',
'enodeb_iface': 'eth1',
'qos': {'enable': False},
'access_control': {
'ip_blocklist': [],
'block_agw_local_ips': True,
},
'clean_restart': True,
'mtr_interface': 'mtr0',
}
return config

@classmethod
def getMconfig(cls):
return PipelineD(
allowed_gre_peers=[{'ip': '1.2.3.4/24', 'key': 123}],
)
allowed_gre_peers=[{'ip': '1.2.3.4/24', 'key': 123}],
)

def test_blocking_ip_match(self):
"""
Expand Down Expand Up @@ -508,6 +510,7 @@ def test_blocking_ip_match(self):
ipv6_prefix_only=True,
)


class AccessControlTestLocalIpBlockLTEIpV6(AbstractAccessControlTest):
OUTBOUND_TEST_IP1 = '::1'
OUTBOUND_TEST_IP2 = '2020::10'
Expand All @@ -516,27 +519,27 @@ class AccessControlTestLocalIpBlockLTEIpV6(AbstractAccessControlTest):
@classmethod
def getConfig(cls):
config = {
'setup_type': 'LTE',
'allow_unknown_arps': False,
'bridge_name': cls.BRIDGE,
'bridge_ip_address': cls.BRIDGE_IP,
'nat_iface': 'eth2',
'enodeb_iface': 'eth1',
'qos': {'enable': False},
'access_control': {
'ip_blocklist': [],
'block_agw_local_ips': True,
},
'clean_restart': True,
'mtr_interface': 'mtr0',
}
'setup_type': 'LTE',
'allow_unknown_arps': False,
'bridge_name': cls.BRIDGE,
'bridge_ip_address': cls.BRIDGE_IP,
'nat_iface': 'eth2',
'enodeb_iface': 'eth1',
'qos': {'enable': False},
'access_control': {
'ip_blocklist': [],
'block_agw_local_ips': True,
},
'clean_restart': True,
'mtr_interface': 'mtr0',
}
return config

@classmethod
def getMconfig(cls):
return PipelineD(
allowed_gre_peers=[{'ip': '1.2.3.4/24', 'key': 123}],
)
allowed_gre_peers=[{'ip': '1.2.3.4/24', 'key': 123}],
)

def test_blocking_ip_match(self):
"""
Expand Down Expand Up @@ -580,6 +583,7 @@ def _build_default_ip_packet(mac, dst, src):
.set_ether_layer(mac, "00:00:00:00:00:00") \
.build()


def _build_default_ipv6_packet(mac, dst, src):
return IPv6PacketBuilder() \
.set_ip_layer(dst, src) \
Expand Down

0 comments on commit a354e3e

Please sign in to comment.