Skip to content

Commit

Permalink
Fixed corner-case bug in CanonicalHyperCubeSet.
Browse files Browse the repository at this point in the history
Signed-off-by: Tanya <[email protected]>
  • Loading branch information
tanyaveksler committed Jul 4, 2023
1 parent 36661e4 commit 476fe3d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nca/CoreDS/CanonicalHyperCubeSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@ def _contained_in_aux(self, other, all_active_dims): # noqa: C901
if not self._is_last_dimension() and not other._is_last_dimension() and \
not (self.layers[layer])._contained_in_aux(other_sub_elem, all_active_dims[1:]):
return False
if self._is_last_dimension() and not other._is_last_dimension() and \
not other_sub_elem._is_sub_elem_entire_sub_space():
return False
remaining = current_layer_0 - common_part
if remaining:
# continue exploring other's cubes for containment of the remaining part from self
Expand Down
29 changes: 29 additions & 0 deletions tests/classes_unit_tests/testCanonicalHyperCubeSetNew.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from nca.CoreDS.MinDFA import MinDFA
from nca.CoreDS.CanonicalHyperCubeSet import CanonicalHyperCubeSet
from nca.CoreDS.DimensionsManager import DimensionsManager
from nca.CoreDS.Peer import BasePeerSet, IpBlock
from nca.CoreDS.ProtocolSet import ProtocolSet

dimensions = ["src_ports", "ports", "methods", "paths"]
dimensions2 = ["ports", "src_ports", "methods", "paths"]
Expand Down Expand Up @@ -971,6 +973,33 @@ def test_contained_in_new(self):
d = CanonicalHyperCubeSet.create_from_cube(dimensions, [get_str_dfa("x|y|z")], ["paths"])
self.assertTrue(c.contained_in(d))

def test_bug_in_contained(self):
BasePeerSet.reset()
BasePeerSet().add_peer("A")
BasePeerSet().add_peer("B")
BasePeerSet().add_peer("C")
ipv4_block = IpBlock.get_all_ips_block(True)
my_dimensions1 = ["src_peers", "dst_peers"]
my_dimensions2 = ["src_peers", "dst_peers", "protocols"]
conns1 = CanonicalHyperCubeSet.create_from_cube(my_dimensions1,
[BasePeerSet().get_peer_interval_of({"B"}),
BasePeerSet().get_peer_interval_of({"A", "B", "C", ipv4_block})],
my_dimensions1)
conns1.add_cube([BasePeerSet().get_peer_interval_of({"C"}),
BasePeerSet().get_peer_interval_of({"A", ipv4_block})], my_dimensions1)

conns2 = CanonicalHyperCubeSet.create_from_cube(my_dimensions2,
[BasePeerSet().get_peer_interval_of({"B"}),
BasePeerSet().get_peer_interval_of({"B", "C"}),
ProtocolSet.get_non_tcp_protocols()],
my_dimensions2)
conns2.add_cube([BasePeerSet().get_peer_interval_of({"B"}),
BasePeerSet().get_peer_interval_of({"A", ipv4_block})], my_dimensions1)
conns2.add_cube([BasePeerSet().get_peer_interval_of({"C"}),
BasePeerSet().get_peer_interval_of({"A", ipv4_block})], my_dimensions1)
self.assertFalse(conns1.contained_in(conns2))
self.assertTrue(conns2.contained_in(conns1))

def test_subtract_basic(self):
x = CanonicalHyperCubeSet(dimensions)
y = CanonicalHyperCubeSet(dimensions)
Expand Down

0 comments on commit 476fe3d

Please sign in to comment.