예제 #1
0
def build_output_actions(acl_table, output_dict):
    """Implement actions to alter packet/output."""
    output_actions = []
    output_port = None
    ofmsgs = []
    # rewrite any VLAN headers first always
    vlan_actions = rewrite_vlan(acl_table, output_dict)
    if vlan_actions:
        output_actions.extend(vlan_actions)
    if 'set_fields' in output_dict:
        for set_field in output_dict['set_fields']:
            output_actions.append(acl_table.set_field(**set_field))
    if 'port' in output_dict:
        output_port = output_dict['port']
        output_actions.append(valve_of.output_port(output_port))
    if 'ports' in output_dict:
        for output_port in output_dict['ports']:
            output_actions.append(valve_of.output_port(output_port))
    if 'failover' in output_dict:
        failover = output_dict['failover']
        group_id = failover['group_id']
        buckets = []
        for port in failover['ports']:
            buckets.append(
                valve_of.bucket(watch_port=port,
                                actions=[valve_of.output_port(port)]))
        ofmsgs.append(valve_of.groupdel(group_id=group_id))
        ofmsgs.append(valve_of.groupadd_ff(group_id=group_id, buckets=buckets))
        output_actions.append(valve_of.group_act(group_id=group_id))
    return (output_port, output_actions, ofmsgs)
예제 #2
0
def build_output_actions(output_dict):
    """Implement actions to alter packet/output."""
    output_actions = []
    output_port = None
    ofmsgs = []
    # if destination rewriting selected, rewrite it.
    if 'dl_dst' in output_dict:
        output_actions.append(valve_of.set_eth_dst(output_dict['dl_dst']))
    # rewrite any VLAN headers.
    vlan_actions = rewrite_vlan(output_dict)
    if vlan_actions:
        output_actions.extend(vlan_actions)
    if 'port' in output_dict:
        output_port = output_dict['port']
        output_actions.append(valve_of.output_port(output_port))
    if 'failover' in output_dict:
        failover = output_dict['failover']
        group_id = failover['group_id']
        buckets = []
        for port in failover['ports']:
            buckets.append(
                valve_of.bucket(watch_port=port,
                                actions=[valve_of.output_port(port)]))
        ofmsgs.append(valve_of.groupdel(group_id=group_id))
        ofmsgs.append(valve_of.groupadd_ff(group_id=group_id, buckets=buckets))
        output_actions.append(valve_of.group_act(group_id=group_id))
    return (output_port, output_actions, ofmsgs)
예제 #3
0
def build_output_actions(acl_table, output_dict):
    """Implement actions to alter packet/output."""
    output_actions = []
    output_port = None
    ofmsgs = []
    # rewrite any VLAN headers first always
    vlan_actions = rewrite_vlan(acl_table, output_dict)
    if vlan_actions:
        output_actions.extend(vlan_actions)
    if 'set_fields' in output_dict:
        for set_field in output_dict['set_fields']:
            output_actions.append(acl_table.set_field(**set_field))
    if 'port' in output_dict:
        output_port = output_dict['port']
        output_actions.append(valve_of.output_port(output_port))
    if 'ports' in output_dict:
        for output_port in output_dict['ports']:
            output_actions.append(valve_of.output_port(output_port))
    if 'failover' in output_dict:
        failover = output_dict['failover']
        group_id = failover['group_id']
        buckets = []
        for port in failover['ports']:
            buckets.append(valve_of.bucket(
                watch_port=port, actions=[valve_of.output_port(port)]))
        ofmsgs.append(valve_of.groupdel(group_id=group_id))
        ofmsgs.append(valve_of.groupadd_ff(group_id=group_id, buckets=buckets))
        output_actions.append(valve_of.group_act(group_id=group_id))
    return (output_port, output_actions, ofmsgs)
예제 #4
0
 def _build_group_flood_rules(self, vlan, modify, command):
     flood_priority = self.flood_priority
     broadcast_buckets = self._build_group_buckets(vlan, False)
     unicast_buckets = self._build_group_buckets(vlan, vlan.unicast_flood)
     group_id = vlan.vid
     ofmsgs = []
     group_mod_method = valve_of.groupadd
     if modify:
         group_mod_method = valve_of.groupmod
     else:
         ofmsgs.append(
             valve_of.groupdel(group_id=group_id))
         ofmsgs.append(
             valve_of.groupdel(group_id=group_id+valve_of.VLAN_GROUP_OFFSET))
     ofmsgs.append(
         group_mod_method(group_id=group_id, buckets=broadcast_buckets))
     ofmsgs.append(
         group_mod_method(group_id=group_id+valve_of.VLAN_GROUP_OFFSET,
                          buckets=unicast_buckets))
     for unicast_eth_dst, eth_dst, eth_dst_mask in self.FLOOD_DSTS:
         if unicast_eth_dst and not vlan.unicast_flood:
             continue
         group_id = vlan.vid
         if not eth_dst:
             group_id = group_id + valve_of.VLAN_GROUP_OFFSET
         match = self.valve_in_match(
             self.flood_table, vlan=vlan,
             eth_dst=eth_dst, eth_dst_mask=eth_dst_mask)
         ofmsgs.append(self.valve_flowmod(
             self.flood_table,
             match=match,
             command=command,
             inst=[valve_of.apply_actions([valve_of.group_act(group_id)])],
             priority=flood_priority))
         flood_priority += 1
     return ofmsgs
예제 #5
0
def build_ordered_output_actions(acl_table,
                                 output_list,
                                 tunnel_rules=None,
                                 source_id=None):
    """Build actions from ordered ACL output list"""
    output_actions = []
    output_ports = []
    output_ofmsgs = []
    for action in output_list:
        for key, value in action.items():
            if key == 'pop_vlans':
                for _ in range(value):
                    output_actions.append(valve_of.pop_vlan())
            if key == 'vlan_vid':
                output_actions.extend(push_vlan(acl_table, value))
            if key == 'swap_vid':
                output_actions.append(acl_table.set_vlan_vid(value))
            if key == 'vlan_vids':
                for vlan_vid in value:
                    output_actions.extend(push_vlan(acl_table, vlan_vid))
            if key == 'set_fields':
                for set_field in value:
                    output_actions.append(acl_table.set_field(**set_field))
            if key == 'port':
                output_ports.append(value)
                output_actions.append(valve_of.output_port(value))
            if key == 'ports':
                for output_port in value:
                    output_ports.append(output_port)
                    output_actions.append(valve_of.output_port(output_port))
            if key == 'failover':
                group_id = value['group_id']
                buckets = []
                for port in value['ports']:
                    buckets.append(
                        valve_of.bucket(watch_port=port,
                                        actions=[valve_of.output_port(port)]))
                output_ofmsgs.append(valve_of.groupdel(group_id=group_id))
                output_ofmsgs.append(
                    valve_of.groupadd_ff(group_id=group_id, buckets=buckets))
                output_actions.append(valve_of.group_act(group_id=group_id))
            if key == 'tunnel' and tunnel_rules and source_id is not None:
                source_rule = tunnel_rules[value][source_id]
                _, tunnel_actions, tunnel_ofmsgs = build_output_actions(
                    acl_table, source_rule)
                output_actions.extend(tunnel_actions)
                tunnel_ofmsgs.extend(tunnel_ofmsgs)
    return (output_ports, output_actions, output_ofmsgs)
예제 #6
0
 def _update_nexthop_group(self, is_updated, resolved_ip_gw,
                           vlan, in_port, eth_src):
     group_mod_method = None
     group_id = None
     buckets = self._nexthop_group_buckets(vlan, in_port, eth_src)
     ofmsgs = []
     if is_updated:
         group_mod_method = valve_of.groupmod
         group_id = self.ip_gw_to_group_id[resolved_ip_gw]
     else:
         group_mod_method = valve_of.groupadd
         group_id = self._group_id_from_ip_gw(resolved_ip_gw)
         self.ip_gw_to_group_id[resolved_ip_gw] = group_id
         ofmsgs.append(valve_of.groupdel(group_id=group_id))
     ofmsgs.append(
         group_mod_method(group_id=group_id, buckets=buckets))
     return ofmsgs
예제 #7
0
def build_output_actions(acl_table,
                         output_dict,
                         tunnel_rules=None,
                         source_id=None):
    """Implement actions to alter packet/output."""
    if isinstance(output_dict, (list, tuple)):
        return build_ordered_output_actions(acl_table, output_dict,
                                            tunnel_rules, source_id)
    output_actions = []
    output_port = None
    ofmsgs = []
    # rewrite any VLAN headers first always
    vlan_actions = rewrite_vlan(acl_table, output_dict)
    if vlan_actions:
        output_actions.extend(vlan_actions)
    if 'set_fields' in output_dict:
        for set_field in output_dict['set_fields']:
            output_actions.append(acl_table.set_field(**set_field))
    if 'port' in output_dict:
        output_port = output_dict['port']
        output_actions.append(valve_of.output_port(output_port))
    if 'ports' in output_dict:
        for output_port in output_dict['ports']:
            output_actions.append(valve_of.output_port(output_port))
    if 'failover' in output_dict:
        failover = output_dict['failover']
        group_id = failover['group_id']
        buckets = []
        for port in failover['ports']:
            buckets.append(
                valve_of.bucket(watch_port=port,
                                actions=[valve_of.output_port(port)]))
        ofmsgs.append(valve_of.groupdel(group_id=group_id))
        ofmsgs.append(valve_of.groupadd_ff(group_id=group_id, buckets=buckets))
        output_actions.append(valve_of.group_act(group_id=group_id))
    if 'tunnel' in output_dict and tunnel_rules and source_id is not None:
        tunnel_id = output_dict['tunnel']
        source_rule = tunnel_rules[tunnel_id][source_id]
        _, tunnel_actions, tunnel_ofmsgs = build_output_actions(
            acl_table, source_rule)
        output_actions.extend(tunnel_actions)
        tunnel_ofmsgs.extend(tunnel_ofmsgs)
    return (output_port, output_actions, ofmsgs)
예제 #8
0
 def test_delete_order(self):
     """Test delete ordering/deupdlication."""
     global_groupdel = valve_of.groupdel(group_id=valve_of.ofp.OFPG_ALL)
     global_flowdel = valve_of.flowmod(cookie=None,
                                       hard_timeout=None,
                                       idle_timeout=None,
                                       match_fields=None,
                                       out_port=None,
                                       table_id=valve_of.ofp.OFPTT_ALL,
                                       inst=(),
                                       priority=0,
                                       command=valve_of.ofp.OFPFC_DELETE,
                                       out_group=valve_of.ofp.OFPG_ANY)
     flowdel = valve_of.flowmod(cookie=None,
                                hard_timeout=None,
                                idle_timeout=None,
                                match_fields=None,
                                out_port=None,
                                table_id=9,
                                inst=(),
                                priority=0,
                                command=valve_of.ofp.OFPFC_DELETE,
                                out_group=valve_of.ofp.OFPG_ANY)
     flow = valve_of.output_port(1)
     flows = [flowdel, flow, flow, flow, global_flowdel, global_groupdel]
     reordered = valve_of.valve_flowreorder(flows, use_barriers=True)
     reordered_str = [str(flow) for flow in reordered]
     # global deletes come first
     self.assertTrue(valve_of.is_global_groupdel(reordered[0]),
                     msg=reordered)
     self.assertTrue(valve_of.is_global_flowdel(reordered[1]),
                     msg=reordered)
     # with a berrier
     self.assertEqual(str(valve_of.barrier()),
                      str(reordered[2]),
                      msg=reordered)
     # without the individual delete
     self.assertTrue(str(flowdel) not in reordered_str, msg=reordered)
     # with regular flow last
     self.assertEqual(str(flow), reordered_str[-1], msg=reordered)
예제 #9
0
 def delete_all(self):
     """Delete all groups."""
     self.entries = {}
     return valve_of.groupdel()
예제 #10
0
 def delete(self):
     """Return flow to delete an existing group entry."""
     if self.group_id in self.table.entries:
         del self.table.entries[self.group_id]
     return valve_of.groupdel(group_id=self.group_id)
예제 #11
0
 def delete_all(self):
     """Delete all groups."""
     self.entries = {}
     return valve_of.groupdel()
예제 #12
0
 def delete(self):
     """Return flow to delete an existing group entry."""
     if self.group_id in self.table.entries:
         del self.table.entries[self.group_id]
     return valve_of.groupdel(group_id=self.group_id)
예제 #13
0
 def delete(self):
     if self.group_id in self.table.entries:
         del self.table.entries[self.group_id]
     return valve_of.groupdel(group_id=self.group_id)