Ejemplo n.º 1
0
 def generate_classifier(self):
     inner_classifier = self.policies[0].compile()
     classifier = Classifier([])
     for r in inner_classifier.rules:
         action = r.actions[0]
         if action == identity:
             classifier.rules.append(Rule(r.match,[drop]))
         elif action == drop:
             classifier.rules.append(Rule(r.match,[identity]))
         else:
             raise TypeError  # TODO MAKE A CompileError TYPE
     return classifier
Ejemplo n.º 2
0
def json_to_classifier(fname, qdict, multistage):
    from pyretic.core.classifier import Rule, Classifier
    data = json.loads(fname)
    rules = []
    for sw_tbl in data:
        switch_id = sw_tbl['switch_id']
        for rule in sw_tbl['tbl']:
            prio = rule['priority']
            m = create_match(rule['pattern'], switch_id)
            action = create_action(rule['action'], multistage)
            queries = get_queries_from_names(rule['queries'], qdict)
            if rule['queries']:
                pyrule = Rule(m, action | queries, [None], "netkat_query")
            else:
                pyrule = Rule(m, action | queries, [None], "netkat")
            rules.append((prio, pyrule))
    #rules.sort()
    rules = [v for (k,v) in rules]
    return Classifier(rules)
Ejemplo n.º 3
0
def json_to_classifier(fname, qdict, multistage, vlan_offset_nbits):
    from pyretic.core.classifier import Rule, Classifier
    data = json.loads(fname)
    rules = []
    for sw_tbl in data:
        switch_id = sw_tbl['switch_id']
        for rule in sw_tbl['tbl']:
            prio = rule['priority']
            m = create_match(rule['pattern'], switch_id, vlan_offset_nbits)
            (action, susp_vlan) = create_action(rule['action'], multistage,
                                                vlan_offset_nbits)
            if susp_vlan:
                action = adjust_vlan_fields(m, action)
            # This check allows classifier construction to proceed whether or
            # not there's a "queries" field in the rule.
            if 'queries' in rule and rule['queries']:
                queries = get_queries_from_names(rule['queries'], qdict)
                pyrule = Rule(m, queries | action, [None], "netkat_query")
            else:
                pyrule = Rule(m, action, [None], "netkat")
            rules.append((prio, pyrule))
    #rules.sort()
    rules = [v for (k, v) in rules]
    return Classifier(rules)
Ejemplo n.º 4
0
 def generate_classifier(self):
     return Classifier([Rule(identity,{self})])
Ejemplo n.º 5
0
 def generate_classifier(self):
     return Classifier([Rule(identity,{Controller})])
Ejemplo n.º 6
0
 def generate_classifier(self):
     if self.has_virtual_headers:
         r = Rule(identity,{Controller})
     else:
         r = Rule(identity,{self})
     return Classifier([r])
Ejemplo n.º 7
0
 def generate_classifier(self):
     r1 = Rule(self,{identity})
     r2 = Rule(identity,set())
     return Classifier([r1, r2])
Ejemplo n.º 8
0
 def generate_classifier(self):
     r1 = Rule(self,[identity])
     r2 = Rule(identity,[drop])
     return Classifier([r1, r2])