Skip to content
Snippets Groups Projects
Commit c9dcf813 authored by Martin Teichmann's avatar Martin Teichmann
Browse files

remove old Else version

parent 865515e2
No related branches found
No related tags found
2 merge requests!9support Leybold turbo pump,!8Draft: move the index field to the end of packet
...@@ -283,9 +283,6 @@ class Elser: ...@@ -283,9 +283,6 @@ class Elser:
def __exit__(self, exc_type, exc, tb): def __exit__(self, exc_type, exc, tb):
self.comp.__exit__(exc_type, exc, tb) self.comp.__exit__(exc_type, exc, tb)
def Else(self):
return self.comp.Else()
class Comparison(ABC): class Comparison(ABC):
"""Base class for all logical operations""" """Base class for all logical operations"""
...@@ -865,9 +862,9 @@ class MemoryDesc: ...@@ -865,9 +862,9 @@ class MemoryDesc:
value = before & ~(1 << fmt[0]) value = before & ~(1 << fmt[0])
except AssembleError: except AssembleError:
with ebpf.wtmp: with ebpf.wtmp:
with value as cond: with value as Else:
ebpf.wtmp = before | (1 << fmt[0]) ebpf.wtmp = before | (1 << fmt[0])
with cond.Else(): with Else:
ebpf.wtmp = before & ~(1 << fmt[0]) ebpf.wtmp = before & ~(1 << fmt[0])
else: else:
mask = ((1 << fmt[1]) - 1) << fmt[0] mask = ((1 << fmt[1]) - 1) << fmt[0]
......
...@@ -367,31 +367,6 @@ class Tests(TestCase): ...@@ -367,31 +367,6 @@ class Tests(TestCase):
Instruction(opcode=0xb7, dst=0, src=0, off=0, imm=1)]) Instruction(opcode=0xb7, dst=0, src=0, off=0, imm=1)])
def test_with(self): def test_with(self):
e = EBPF()
e.owners = set(range(11))
with e.r2 > 3 as cond:
e.r2 = 5
with cond.Else():
e.r6 = 7
with e.r2:
e.r3 = 2
with e.r4 > 3 as cond:
e.r5 = 7
with cond.Else():
e.r7 = 8
self.assertEqual(e.opcodes,
[Instruction(opcode=0xb5, dst=2, src=0, off=2, imm=3),
Instruction(opcode=0xb7, dst=2, src=0, off=0, imm=5),
Instruction(opcode=0x5, dst=0, src=0, off=1, imm=0),
Instruction(opcode=O.MOV+O.LONG, dst=6, src=0, off=0, imm=7),
Instruction(opcode=O.JEQ, dst=2, src=0, off=1, imm=0),
Instruction(opcode=O.MOV+O.LONG, dst=3, src=0, off=0, imm=2),
Instruction(opcode=O.JLE, dst=4, src=0, off=2, imm=3),
Instruction(opcode=O.MOV+O.LONG, dst=5, src=0, off=0, imm=7),
Instruction(opcode=O.JMP, dst=0, src=0, off=1, imm=0),
Instruction(opcode=O.MOV+O.LONG, dst=7, src=0, off=0, imm=8)])
def test_with_new(self):
e = EBPF() e = EBPF()
e.owners = set(range(11)) e.owners = set(range(11))
with e.r2 > 3 as Else: with e.r2 > 3 as Else:
...@@ -420,10 +395,10 @@ class Tests(TestCase): ...@@ -420,10 +395,10 @@ class Tests(TestCase):
e = EBPF() e = EBPF()
with e.r1 & 1 as cond: with e.r1 & 1 as cond:
e.r0 = 2 e.r0 = 2
with e.r1 & 7 as cond: with e.r1 & 7 as Else:
e.r0 = 2 e.r0 = 2
e.r1 = 4 e.r1 = 4
with cond.Else(): with Else:
e.r0 = 3 e.r0 = 3
self.assertEqual(e.opcodes, [ self.assertEqual(e.opcodes, [
Instruction(opcode=69, dst=1, src=0, off=1, imm=1), Instruction(opcode=69, dst=1, src=0, off=1, imm=1),
...@@ -438,11 +413,11 @@ class Tests(TestCase): ...@@ -438,11 +413,11 @@ class Tests(TestCase):
def test_with_and(self): def test_with_and(self):
e = EBPF() e = EBPF()
e.owners = set(range(11)) e.owners = set(range(11))
with (e.r2 > 3) & (e.r3 > 2) as cond: with (e.r2 > 3) & (e.r3 > 2) as Else:
e.r1 = 5 e.r1 = 5
with (e.r2 > 2) & (e.r1 < 2) as cond: with (e.r2 > 2) & (e.r1 < 2) as Else:
e.r2 = 5 e.r2 = 5
with cond.Else(): with Else:
e.r3 = 7 e.r3 = 7
self.assertEqual(e.opcodes, [ self.assertEqual(e.opcodes, [
Instruction(opcode=O.JLE, dst=2, src=0, off=2, imm=3), Instruction(opcode=O.JLE, dst=2, src=0, off=2, imm=3),
...@@ -457,12 +432,12 @@ class Tests(TestCase): ...@@ -457,12 +432,12 @@ class Tests(TestCase):
def test_with_or(self): def test_with_or(self):
e = EBPF() e = EBPF()
e.owners = set(range(11)) e.owners = set(range(11))
with (e.r2 > 3) | (e.r3 > 2) as cond: with (e.r2 > 3) | (e.r3 > 2) as Else:
e.r1 = 5 e.r1 = 5
with (e.r2 > 2) | (e.r1 > 2) as cond: with (e.r2 > 2) | (e.r1 > 2) as Else:
e.r2 = 5 e.r2 = 5
e.r5 = 4 e.r5 = 4
with cond.Else(): with Else:
e.r3 = 7 e.r3 = 7
e.r4 = 3 e.r4 = 3
self.maxDiff = None self.maxDiff = None
...@@ -481,9 +456,9 @@ class Tests(TestCase): ...@@ -481,9 +456,9 @@ class Tests(TestCase):
def test_comp_binary(self): def test_comp_binary(self):
e = EBPF() e = EBPF()
e.owners = {1, 2, 3, 5} e.owners = {1, 2, 3, 5}
with e.r1 + e.r3 > 3 as cond: with e.r1 + e.r3 > 3 as Else:
e.r0 = 5 e.r0 = 5
with cond.Else(): with Else:
e.r0 = 7 e.r0 = 7
tgt = e.jumpIf(e.r0 < e.r2 + e.r5) tgt = e.jumpIf(e.r0 < e.r2 + e.r5)
...@@ -638,10 +613,10 @@ class Tests(TestCase): ...@@ -638,10 +613,10 @@ class Tests(TestCase):
def test_with_data(self): def test_with_data(self):
e = EBPF() e = EBPF()
with e.r1 > 0 as cond: with e.r1 > 0 as Else:
e.r2 = 3 e.r2 = 3
e.r3 = 5 e.r3 = 5
with cond.Else(): with Else:
with self.assertRaises(AssembleError): with self.assertRaises(AssembleError):
e.r0 = e.r2 e.r0 = e.r2
e.r3 = 5 e.r3 = 5
...@@ -751,7 +726,7 @@ class Tests(TestCase): ...@@ -751,7 +726,7 @@ class Tests(TestCase):
e = XDP(license="GPL") e = XDP(license="GPL")
with e.packetSize > 100 as p: with e.packetSize > 100 as p:
e.r3 = p.pH[22] e.r3 = p.pH[22]
with p.Else(): with p.Else:
e.r3 = 77 e.r3 = 77
self.assertEqual(e.opcodes, [ self.assertEqual(e.opcodes, [
Instruction(opcode=O.LD+O.W, dst=9, src=1, off=0, imm=0), Instruction(opcode=O.LD+O.W, dst=9, src=1, off=0, imm=0),
......
...@@ -275,16 +275,16 @@ class EtherXDP(XDP): ...@@ -275,16 +275,16 @@ class EtherXDP(XDP):
self.r[dst] += 4 * self.r3 self.r[dst] += 4 * self.r3
self.r4 = self.mB[self.r[dst]] self.r4 = self.mB[self.r[dst]]
# we lost a packet # we lost a packet
with p.pB[IDX0] == self.r4 as cond: with p.pB[IDX0] == self.r4 as Else:
self.mI[self.r[dst]] += 1 + (self.r4 & 1) self.mI[self.r[dst]] += 1 + (self.r4 & 1)
# normal case: two packets on the wire # normal case: two packets on the wire
with cond.Else(), ((p.pB[IDX0] + 1 & 0xff) == self.r4) \ with Else, ((p.pB[IDX0] + 1 & 0xff) == self.r4) \
| (p.pB[IDX0] == 0) as c2: | (p.pB[IDX0] == 0) as Else:
self.mI[self.r[dst]] += 1 self.mI[self.r[dst]] += 1
with self.r4 & 1: # last one was active with self.r4 & 1: # last one was active
p.pB[IDX0] = self.mB[self.r[dst]] p.pB[IDX0] = self.mB[self.r[dst]]
self.exit(XDPExitCode.TX) self.exit(XDPExitCode.TX)
with c2.Else(): with Else:
self.exit(XDPExitCode.PASS) self.exit(XDPExitCode.PASS)
p.pB[IDX0] = self.mB[self.r[dst]] p.pB[IDX0] = self.mB[self.r[dst]]
self.r2 = self.get_fd(self.programs) self.r2 = self.get_fd(self.programs)
......
...@@ -104,9 +104,9 @@ class PacketArray: ...@@ -104,9 +104,9 @@ class PacketArray:
class Packet: class Packet:
def __init__(self, ebpf, comp, no): def __init__(self, ebpf, Else, no):
self.ebpf = ebpf self.ebpf = ebpf
self.comp = comp self.Else = Else
self.no = no self.no = no
self.pB = PacketArray(self.ebpf, self.no, self.ebpf.mB) self.pB = PacketArray(self.ebpf, self.no, self.ebpf.mB)
...@@ -114,9 +114,6 @@ class Packet: ...@@ -114,9 +114,6 @@ class Packet:
self.pI = PacketArray(self.ebpf, self.no, self.ebpf.mI) self.pI = PacketArray(self.ebpf, self.no, self.ebpf.mI)
self.pQ = PacketArray(self.ebpf, self.no, self.ebpf.mQ) self.pQ = PacketArray(self.ebpf, self.no, self.ebpf.mQ)
def Else(self):
return self.comp.Else()
class PacketSize: class PacketSize:
def __init__(self, ebpf): def __init__(self, ebpf):
...@@ -126,15 +123,15 @@ class PacketSize: ...@@ -126,15 +123,15 @@ class PacketSize:
def __lt__(self, value): def __lt__(self, value):
e = self.ebpf e = self.ebpf
e.r9 = e.mA[e.r1] e.r9 = e.mA[e.r1]
with e.mA[e.r1 + 4] < e.mA[e.r1] + value as comp: with e.mA[e.r1 + 4] < e.mA[e.r1] + value as Else:
yield Packet(e, comp, 9) yield Packet(e, Else, 9)
@contextmanager @contextmanager
def __gt__(self, value): def __gt__(self, value):
e = self.ebpf e = self.ebpf
e.r9 = e.mA[e.r1] e.r9 = e.mA[e.r1]
with e.mA[e.r1 + 4] > e.mA[e.r1] + value as comp: with e.mA[e.r1 + 4] > e.mA[e.r1] + value as Else:
yield Packet(e, comp, 9) yield Packet(e, Else, 9)
def __le__(self, value): def __le__(self, value):
return self < value + 1 return self < value + 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment