Example #1
0
def mpls_tun1_group(dpath, mod, ofctl):
    """
    MPLS Tunnel1 Label Group
    """
    _LOG.debug("MPLS Tunnel1 Group: %d %s %s", dpath.id, mod, ofctl)

    entry = mod.mpls_label
    cmd = fibcapi.group_mod_cmd(mod.cmd, dpath.ofproto)
    gid = fibcapi.mpls_label_group_id(3, entry.dst_id)

    def _buckets():
        if not ofgroup.is_bucket_needed(dpath, cmd):
            return []

        next_gid = fibcapi.mpls_interface_group_id(entry.ne_id)
        actions = [
            ofaction.push_mpls(fibcapi.ETHTYPE_MPLS),
            ofaction.set_field("mpls_label", entry.new_label),
            ofaction.set_mpls_ttl(64),
            ofaction.group(next_gid),
        ]
        return [dict(actions=actions)]

    group = ofgroup.group_mod(gid, "INDIRECT", _buckets)
    ofctl.mod_group_entry(dpath, group, cmd)
Example #2
0
    def get_next_gid(entry):
        """
        Get Next Group Id
        """
        if entry.ne_id != 0:
            return fibcapi.mpls_interface_group_id(entry.ne_id)
        elif entry.new_dst_id != 0:
            return fibcapi.mpls_label_group_id(3, entry.new_dst_id)

        return None
Example #3
0
 def _writes():
     if not offlow.is_action_needed(dpath, cmd):
         return []
     if entry.g_type == pb.GroupMod.MPLS_INTERFACE:
         return [
             ofaction.group(fibcapi.mpls_interface_group_id(entry.g_id))
         ]
     if entry.g_type == pb.GroupMod.MPLS_SWAP:
         return [ofaction.group(fibcapi.mpls_label_group_id(5, entry.g_id))]
     if entry.g_type == pb.GroupMod.MPLS_FF:
         return [ofaction.group(fibcapi.mpls_ff_group_id(entry.g_id))]
     if entry.g_type == pb.GroupMod.MPLS_ECMP:
         return [ofaction.group(fibcapi.mpls_ecmp_group_id(entry.g_id))]
     return []
Example #4
0
    def _writes():
        if not offlow.is_action_needed(dpath, cmd):
            return []

        writes = [ofaction.dec_nw_ttl()]
        if entry.g_type == pb.GroupMod.L3_UNICAST:
            writes.append(
                ofaction.group(fibcapi.l3_unicast_group_id(entry.g_id)))
        elif entry.g_type == pb.GroupMod.L3_ECMP:
            writes.append(ofaction.group(fibcapi.l3_ecmp_group_id(entry.g_id)))
        elif entry.g_type == pb.GroupMod.MPLS_L3_VPN:
            writes.append(
                ofaction.group(fibcapi.mpls_label_group_id(2, entry.g_id)))
        else:
            pass

        return writes
Example #5
0
def mpls_l3_vpn_group(dpath, mod, ofctl, mpls_bos=True):
    """
    MPLS L3 VPN Group
    """
    _LOG.debug("MPLS L3 VPN Group: %d %s %s", dpath.id, mod, ofctl)

    def get_next_gid(entry):
        """
        Get Next Group Id
        """
        if entry.ne_id != 0:
            return fibcapi.mpls_interface_group_id(entry.ne_id)
        elif entry.new_dst_id != 0:
            return fibcapi.mpls_label_group_id(3, entry.new_dst_id)

        return None

    entry = mod.mpls_label
    cmd = fibcapi.group_mod_cmd(mod.cmd, dpath.ofproto)
    gid = fibcapi.mpls_label_group_id(2, entry.dst_id)

    def _buckets():
        if not ofgroup.is_bucket_needed(dpath, cmd):
            return []

        next_gid = get_next_gid(entry)
        actions = [
            ofaction.push_mpls(fibcapi.ETHTYPE_MPLS),
            ofaction.set_field("mpls_label", entry.new_label),
        ]

        if mpls_bos:
            actions.append(ofaction.set_field("mpls_bos", 1))

        actions.append(ofaction.set_mpls_ttl(64))
        actions.append(ofaction.group(next_gid))

        return [dict(actions=actions)]

    group = ofgroup.group_mod(gid, "INDIRECT", _buckets)
    ofctl.mod_group_entry(dpath, group, cmd)