summaryrefslogtreecommitdiffhomepage
path: root/config/bgp_configs.go
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-04-27 11:28:32 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-05-10 21:12:30 +0900
commit32f7faa8e7f83c20e50a37e44ba01a498939f574 (patch)
tree014b7755fb5cd873f2ea7bfd9ece4c9f846475ad /config/bgp_configs.go
parent0f88373949e2eed7a9dbcd1ebac64d76e54f6d40 (diff)
config: Enable to configure VRF via config file
This patch enables to configure VRF tables by using config file. This feature is useful when using VRF-Neighbor feature. Example of Usage: ```toml [[vrfs]] [vrfs.config] name = "vrf1" id = 1 rd = "65000:100" both-rt-list = ["65000:100"] ``` Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'config/bgp_configs.go')
-rw-r--r--config/bgp_configs.go124
1 files changed, 124 insertions, 0 deletions
diff --git a/config/bgp_configs.go b/config/bgp_configs.go
index 402bff40..062ef8f7 100644
--- a/config/bgp_configs.go
+++ b/config/bgp_configs.go
@@ -1250,6 +1250,112 @@ func (lhs *Mrt) Equal(rhs *Mrt) bool {
}
// struct for container gobgp:state.
+// Configured states of VRF.
+type VrfState struct {
+ // original -> gobgp:name
+ // Unique name among all VRF instances.
+ Name string `mapstructure:"name" json:"name,omitempty"`
+ // original -> gobgp:id
+ // Unique identifier among all VRF instances.
+ Id uint32 `mapstructure:"id" json:"id,omitempty"`
+ // original -> gobgp:rd
+ // Route Distinguisher for this VRF.
+ Rd string `mapstructure:"rd" json:"rd,omitempty"`
+ // original -> gobgp:import-rt
+ // List of import Route Targets for this VRF.
+ ImportRtList []string `mapstructure:"import-rt-list" json:"import-rt-list,omitempty"`
+ // original -> gobgp:export-rt
+ // List of export Route Targets for this VRF.
+ ExportRtList []string `mapstructure:"export-rt-list" json:"export-rt-list,omitempty"`
+}
+
+// struct for container gobgp:config.
+// Configuration parameters for VRF.
+type VrfConfig struct {
+ // original -> gobgp:name
+ // Unique name among all VRF instances.
+ Name string `mapstructure:"name" json:"name,omitempty"`
+ // original -> gobgp:id
+ // Unique identifier among all VRF instances.
+ Id uint32 `mapstructure:"id" json:"id,omitempty"`
+ // original -> gobgp:rd
+ // Route Distinguisher for this VRF.
+ Rd string `mapstructure:"rd" json:"rd,omitempty"`
+ // original -> gobgp:import-rt
+ // List of import Route Targets for this VRF.
+ ImportRtList []string `mapstructure:"import-rt-list" json:"import-rt-list,omitempty"`
+ // original -> gobgp:export-rt
+ // List of export Route Targets for this VRF.
+ ExportRtList []string `mapstructure:"export-rt-list" json:"export-rt-list,omitempty"`
+ // original -> gobgp:both-rt
+ // List of both import and export Route Targets for this VRF. Each
+ // configuration for import and export Route Targets will be preferred.
+ BothRtList []string `mapstructure:"both-rt-list" json:"both-rt-list,omitempty"`
+}
+
+func (lhs *VrfConfig) Equal(rhs *VrfConfig) bool {
+ if lhs == nil || rhs == nil {
+ return false
+ }
+ if lhs.Name != rhs.Name {
+ return false
+ }
+ if lhs.Id != rhs.Id {
+ return false
+ }
+ if lhs.Rd != rhs.Rd {
+ return false
+ }
+ if len(lhs.ImportRtList) != len(rhs.ImportRtList) {
+ return false
+ }
+ for idx, l := range lhs.ImportRtList {
+ if l != rhs.ImportRtList[idx] {
+ return false
+ }
+ }
+ if len(lhs.ExportRtList) != len(rhs.ExportRtList) {
+ return false
+ }
+ for idx, l := range lhs.ExportRtList {
+ if l != rhs.ExportRtList[idx] {
+ return false
+ }
+ }
+ if len(lhs.BothRtList) != len(rhs.BothRtList) {
+ return false
+ }
+ for idx, l := range lhs.BothRtList {
+ if l != rhs.BothRtList[idx] {
+ return false
+ }
+ }
+ return true
+}
+
+// struct for container gobgp:vrf.
+// VRF instance configurations on the local system.
+type Vrf struct {
+ // original -> gobgp:name
+ // original -> gobgp:vrf-config
+ // Configuration parameters for VRF.
+ Config VrfConfig `mapstructure:"config" json:"config,omitempty"`
+ // original -> gobgp:vrf-state
+ // Configured states of VRF.
+ State VrfState `mapstructure:"state" json:"state,omitempty"`
+}
+
+func (lhs *Vrf) Equal(rhs *Vrf) bool {
+ if lhs == nil || rhs == nil {
+ return false
+ }
+ if !lhs.Config.Equal(&(rhs.Config)) {
+ return false
+ }
+ return true
+}
+
+// struct for container gobgp:state.
// Configuration parameters relating to BMP server.
type BmpServerState struct {
// original -> gobgp:address
@@ -4785,6 +4891,8 @@ type Bgp struct {
RpkiServers []RpkiServer `mapstructure:"rpki-servers" json:"rpki-servers,omitempty"`
// original -> gobgp:bmp-servers
BmpServers []BmpServer `mapstructure:"bmp-servers" json:"bmp-servers,omitempty"`
+ // original -> gobgp:vrfs
+ Vrfs []Vrf `mapstructure:"vrfs" json:"vrfs,omitempty"`
// original -> gobgp:mrt-dump
MrtDump []Mrt `mapstructure:"mrt-dump" json:"mrt-dump,omitempty"`
// original -> gobgp:zebra
@@ -4866,6 +4974,22 @@ func (lhs *Bgp) Equal(rhs *Bgp) bool {
}
}
}
+ if len(lhs.Vrfs) != len(rhs.Vrfs) {
+ return false
+ }
+ {
+ lmap := make(map[string]*Vrf)
+ for i, l := range lhs.Vrfs {
+ lmap[mapkey(i, string(l.Config.Name))] = &lhs.Vrfs[i]
+ }
+ for i, r := range rhs.Vrfs {
+ if l, y := lmap[mapkey(i, string(r.Config.Name))]; !y {
+ return false
+ } else if !r.Equal(l) {
+ return false
+ }
+ }
+ }
if len(lhs.MrtDump) != len(rhs.MrtDump) {
return false
}