예제 #1
0
 def instantiate_fvs(self, fv_value_mapping):
     left = self.left
     right = self.right
     if isinstance(self.left, FreeVariable):
         left = fv_value_mapping.binding[self.left]
     if isinstance(self.right, FreeVariable):
         right = fv_value_mapping.binding[self.right]
     if isinstance(left, Input) and left.is_symbolic:
         left = Input(left.name, fv_value_mapping.binding[left.fv])
     if isinstance(right, Input) and right.is_symbolic:
         left = Input(right.name, fv_value_mapping.binding[right.fv])
     return BoundedGT(left, right)
예제 #2
0
 def instantiate(self, var):
     #print ("my mapping ",self.mapping)
     if isinstance(var, Input):
         if var.is_symbolic:
             return Input(var.name, self.mapping[var.fv])
     elif isinstance(var, Output):
         if var.is_symbolic:
             return Output(var.name, self.mapping[var.fv])
     elif isinstance(var, FreeVariable):
         return self.mapping[var]
     return var
예제 #3
0
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)
예제 #4
0
    def __init__(self, pkt, port_id, state_vars_dict,
                 symbolic_state_vars_dict):
        self.mapping = dict()
        if pkt is not None:
            self.mapping[Input('ethSrc')] = Mac(pkt.ethSrc)
            self.mapping[Input('ethDst')] = Mac(pkt.ethDst)
            self.mapping[Input('ethType')] = EthType(pkt.ethType)
            self.mapping[Input('port_id')] = Port(port_id)
            if pkt.vlan is not None:
                self.mapping[Input('vlan')] = Vlan(pkt.vlan)
                self.mapping[Input('vlanPcp')] = PriorityCode(pkt.vlanPcp)

            if pkt.ip4Src is not None:
                self.mapping[Input('ip4Src')] = IPAddr(pkt.ip4Src)
                self.mapping[Input('ip4Dst')] = IPAddr(pkt.ip4Dst)
                self.mapping[Input('ipProto')] = IPProto(pkt.ipProto)

            if pkt.tcpSrcPort is not None:
                self.mapping[Input('tcpSrcPort')] = TCPPort(pkt.tcpSrcPort)
                self.mapping[Input('tcpSrcPort')] = TCPPort(pkt.tcpDstPort)

        self.state_vars_dict = state_vars_dict
        for _, sv in state_vars_dict.items():
            self.mapping[Input(sv.name)] = sv.vartype(sv.value)
        self.symbolic_state_vars_dict = symbolic_state_vars_dict
예제 #5
0
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()
inv0 = Invariant(
    ActionList([Action([EQ(Input("ip4Src"), IPAddr("127.0.0.3"))])]))
inv = Invariant(
    Implies(
        Match([
            EQ(Input("ip4Src"), IPAddr("10.0.0.1")),
        ]),
        ActionList([Action([EQ(Output("ip4Dst_out"), IPAddr("127.0.0.1"))])])))
"""
inv3 = Invariant(
    Implies(
        Match(

            [
                EQ(
                    Input("ip4Src"),
                    IPAddr("10.0.0.1")
                ),
            ]

        ),
        ActionList(
            [
예제 #6
0
state_var_list = list()
invariants = list()
precedences = list()
reactions = list()

symbolic_state_var_list = list()

sv = StateVar("block", Bool, False)
state_var_list.append(sv)
ssv = SymbolicStateVar("learnt", IPAddr, Bool, False)
symbolic_state_var_list.append(ssv)
tt = Invariant(
    Implies(
        Match([
            EQ(Input("ip4Dst"), FreeVariable("X", "IPAddr")),
            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))
            ])
        ])))
예제 #7
0
from macros.expression import Implies, Match, ActionList, EQ, GT, NEQ, Action
from macros.types import IPAddr, Port, Bool
from macros.variables import Input, Output, FreeVariable, StateVar, SymbolicStateVar
from macros.macro import Invariant, Precedence, Reaction

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))
예제 #8
0
from macros.expression import Implies, Match, ActionList, EQ, Action, And, NEQ
from macros.macro import Reaction, PrecedenceFactory
from macros.types import IPAddr, Port
from macros.variables import Input, Output

invariants = list()
precedences = list()
reactions = list()
# ip4Src = 10.0.0.3 -> X ( ip4Src = 10.0.0.1 -> port_out =  2)
state_var_list = list()
symbolic_state_var_list = list()
react1 = Reaction(
    Match(
        [
            EQ(
                Input("ip4Src"), IPAddr("10.0.0.3")
            )
        ]
    )
    , Implies(
        Match(

            [
                EQ(
                    Input("ip4Src"),
                    IPAddr("10.0.0.1")
                ),
            ]

        ),
        ActionList(
예제 #9
0
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()
inv1 = Invariant(
            Implies(
            Match(

                [
                    EQ(
                        Input("ip4Src"),
                        IPAddr("10.0.0.1")
                        ),
                    ]

                ),
            ActionList(
                [
                    Action(
                        [
                            EQ(
                                Output("port_id_out"),
                                Port(2)
                                )
                            ]
                        )
                    ]