from macros.expression import Implies, Match, ActionList, EQ, GT, NEQ, Action from macros.types import IPAddr, Port from macros.variables import Input, Output, FreeVariable from macros.macro import Invariant, Precedence, Reaction invariants = list() precedences = list() reactions = list() react1 = Reaction( Match([EQ(Input("ip4Src"), IPAddr("10.0.0.3"))]), Implies(Match([ EQ(Input("ip4Src"), IPAddr("10.0.0.1")), ]), ActionList([Action([EQ(Output("port_id_out"), Port(2))])])), Match([EQ(Input("ip4Src"), IPAddr("10.0.0.4"))])) react2 = Reaction( Match([EQ(Input("ip4Src"), IPAddr("10.0.0.3"))]), Implies(Match([ EQ(Input("ip4Src"), IPAddr("10.0.0.2")), ]), ActionList([Action([EQ(Output("port_id_out"), Port(1))])])), Match([EQ(Input("ip4Src"), IPAddr("10.0.0.4"))])) reactions.append(react1) reactions.append(react2) #reactions.append(react)
EQ(Input("learnt", FreeVariable("X", "IPAddr")), Bool(False)) ]), ActionList([Action([EQ(Output("port_id_out"), Port(100))])]))) tt2 = Invariant( Implies( Match([ EQ(Input("ip4Src"), FreeVariable("X", "IPAddr")), ]), ActionList([ Action([ EQ(Output("learnt_out", FreeVariable("X", "IPAddr")), Bool(True)) ]) ]))) react1 = Reaction( Match([ EQ(Input("ip4Src"), FreeVariable("X", "IPAddr")), EQ(Input("port_id"), FreeVariable("Y", "Port")), ]), Implies( Match([EQ(Input("ip4Dst"), FreeVariable("X", "IPAddr"))]), ActionList( [Action([EQ(Output("port_id_out"), FreeVariable("Y", "Port"))])])), Match([EQ(Input("ip4Src"), IPAddr("10.0.0.255"))])) invariants.append(tt) invariants.append(tt2) reactions.append(react1)
""" inv2 = Invariant( Implies( Match([ EQ(Input("ip4Src"), IPAddr("127.0.0.1")), ]), ActionList([Action([EQ(IPAddr("127.0.0.1"), IPAddr("127.0.0.1"))])]))) inv3 = Invariant(ActionList([Action([GT(Output("port_id_out"), Port(127))])])) invariants.append(inv) invariants.append(inv2) invariants.append(inv3) react = Reaction( Match([ EQ(Input("ethSrc"), FreeVariable("X", "Mac")), EQ(Input("port_id"), FreeVariable("P", "Port")) ]), Implies( Match([EQ(Input("ethDst"), FreeVariable("X", "Mac"))]), ActionList([ Action([ EQ(Output("port_id_out"), FreeVariable("P", "Port")), GT(FreeVariable("P", "Port"), Port(3)) ]), Action([NEQ(Output("port_id_out"), Port(3))]), Action([GT(Port(5), Port(4))]) ])), Match([EQ(IPAddr("127.0.0.1"), IPAddr("127.0.0.1"))])) reactions.append(react)
state_var_list = list() invariants = list() precedences = list() reactions = list() sv = StateVar("block", Bool, False) state_var_list.append(sv) prec1 = Precedence.create( Match([EQ(Input("ip4Src"), IPAddr("10.0.0.2"))]), ActionList([Action([EQ(Output("block_out"), Bool(True))])])) precedences.append(prec1) react1 = Reaction(Match([EQ(Input("ip4Src"), IPAddr("10.0.0.4"))]), ActionList([Action([EQ(Output("block_out"), Bool(True))])]), Match([EQ(Input("ip4Src"), IPAddr("10.0.0.3"))])) react2 = Reaction(Match([EQ(Input("ip4Src"), IPAddr("10.0.0.3"))]), ActionList([Action([EQ(Output("block_out"), Bool(False))])]), Match([EQ(Input("ip4Src"), IPAddr("10.0.0.4"))])) inv = Invariant( Implies( Match([ EQ(Input("ip4Src"), IPAddr("10.0.0.1")), EQ(Input("block"), Bool(False)) ]), ActionList([Action([EQ(Output("port_id_out"), Port(2))])]))) inv2 = Invariant( Implies( Match([