github.com/osrg/gobgp@v2.0.0+incompatible/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/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 } 29 30 func (v *Vrf) Clone() *Vrf { 31 f := func(rt []bgp.ExtendedCommunityInterface) []bgp.ExtendedCommunityInterface { 32 l := make([]bgp.ExtendedCommunityInterface, 0, len(rt)) 33 return append(l, rt...) 34 } 35 return &Vrf{ 36 Name: v.Name, 37 Id: v.Id, 38 Rd: v.Rd, 39 ImportRt: f(v.ImportRt), 40 ExportRt: f(v.ExportRt), 41 } 42 } 43 44 func isLastTargetUser(vrfs map[string]*Vrf, target bgp.ExtendedCommunityInterface) bool { 45 for _, vrf := range vrfs { 46 for _, rt := range vrf.ImportRt { 47 if target.String() == rt.String() { 48 return false 49 } 50 } 51 } 52 return true 53 }