github.com/osrg/gobgp/v3@v3.30.0/internal/pkg/table/vrf.go (about)

     1  // Copyright (C) 2014-2016 Nippon Telegraph and Telephone Corporation.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    12  // implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  package table
    17  
    18  import (
    19  	"github.com/osrg/gobgp/v3/pkg/packet/bgp"
    20  )
    21  
    22  type Vrf struct {
    23  	Name      string
    24  	Id        uint32
    25  	Rd        bgp.RouteDistinguisherInterface
    26  	ImportRt  []bgp.ExtendedCommunityInterface
    27  	ExportRt  []bgp.ExtendedCommunityInterface
    28  	MplsLabel uint32
    29  }
    30  
    31  func (v *Vrf) Clone() *Vrf {
    32  	f := func(rt []bgp.ExtendedCommunityInterface) []bgp.ExtendedCommunityInterface {
    33  		l := make([]bgp.ExtendedCommunityInterface, 0, len(rt))
    34  		return append(l, rt...)
    35  	}
    36  	return &Vrf{
    37  		Name:      v.Name,
    38  		Id:        v.Id,
    39  		Rd:        v.Rd,
    40  		ImportRt:  f(v.ImportRt),
    41  		ExportRt:  f(v.ExportRt),
    42  		MplsLabel: v.MplsLabel,
    43  	}
    44  }
    45  
    46  func isLastTargetUser(vrfs map[string]*Vrf, target bgp.ExtendedCommunityInterface) bool {
    47  	for _, vrf := range vrfs {
    48  		for _, rt := range vrf.ImportRt {
    49  			if target.String() == rt.String() {
    50  				return false
    51  			}
    52  		}
    53  	}
    54  	return true
    55  }