Skip to content

Commit

Permalink
Add prefix-list support.
Browse files Browse the repository at this point in the history
  • Loading branch information
kishiguro committed Mar 12, 2018
1 parent d086588 commit 7e972b4
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 109 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ func (this *ConfigComponent) Stop() component.Component {
RelayExitFunc()
QuaggaExit()
OspfVrfExit()
DistributeListExit()
GobgpWanExit()

return this
Expand Down
2 changes: 2 additions & 0 deletions config/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ loop:
go SubscribeRemoteAdd(stream, msg)
case rpc.ConfigType_SUBSCRIBE_MULTI:
go SubscribeRemoteAddMulti(stream, msg)
case rpc.ConfigType_SUBSCRIBE_REQUEST:
go SubscribeAdd(stream, msg)
case rpc.ConfigType_SET:
YangConfigPush(msg.Path)
case rpc.ConfigType_DELETE:
Expand Down
10 changes: 6 additions & 4 deletions config/ospf.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import (
)

type Ospf struct {
Network string `mapstructure:"network" json:"network,omitempty"`
Area uint32 `mapstructure:"area" json:"area,omitempty"`
InterfaceIps []InterfaceIp `mapstructure:"interfaces" json:"interfaces,omitempty"`
Interface string `mapstructure:"interface" json:"interface,omitempty"` // Deplicated from 2.4
Network string `mapstructure:"network" json:"network,omitempty"`
Area uint32 `mapstructure:"area" json:"area,omitempty"`
InterfaceIps []InterfaceIp `mapstructure:"interfaces" json:"interfaces,omitempty"`
Interface string `mapstructure:"interface" json:"interface,omitempty"` // Deplicated from 2.4
PrimaryList []DistributeListEntry `mapstructure:"primary-distribute-list" json:"primary-distribute-list,omitempty"`
BackupList []DistributeListEntry `mapstructure:"backup-distribute-list" json:"backup-distribute-list,omitempty"`
}

type OspfArray []Ospf
Expand Down
87 changes: 82 additions & 5 deletions config/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ type SubPath interface {
}

type SubPathBase struct {
path *Path
//cmd []*Command
path *Path
pathcmd map[string][]*Command
sync bool
json bool
Expand Down Expand Up @@ -106,9 +105,23 @@ func (subPath *SubPathBase) CommandClear() {

func (subPath *SubPathRemote) Commit() {
fmt.Println("[cmd]SubPathRemote:Commit() Start", subPath.path.Name)
for _, pathcmd := range subPath.pathcmd {
for _, cmd := range pathcmd {
subPath.sub.SendCommand(cmd)
for pathstr, pathcmd := range subPath.pathcmd {
if subPath.json {
fmt.Println("XXX JSON Commit", pathstr)
path := strings.Split(pathstr, "|")
config := configCandidate.LookupByPath(path)
json := "{}"
if config != nil {
json = config.JsonMarshal()
} else {
fmt.Println("XXXX empty JSON", path)
}
subPath.sub.SendJSON(path, json)
fmt.Println("JSON:", json)
} else {
for _, cmd := range pathcmd {
subPath.sub.SendCommand(cmd)
}
}
}
fmt.Println("[cmd]SubPathRemote:Commit() End", subPath.path.Name)
Expand Down Expand Up @@ -158,6 +171,19 @@ func (sub *Subscriber) SendMessage(typ rpc.ConfigType, path []string) {
sub.stream.Send(msg)
}

func (sub *Subscriber) SendJSON(path []string, json string) {
if sub.stream == nil {
fmt.Println("[cmd]SendJSON: sub.stream is nil")
return
}
msg := &rpc.ConfigReply{
Type: rpc.ConfigType_JSON_CONFIG,
Path: path,
Json: json,
}
sub.stream.Send(msg)
}

func (sub *Subscriber) SendCommand(cmd *Command) {
if cmd.set {
fmt.Println("[cmd]SendCommand set:", cmd.cmds)
Expand Down Expand Up @@ -512,6 +538,57 @@ func SubscribeRemoteAdd(stream rpc.Config_DoConfigServer, req *rpc.ConfigRequest
}
}

func SubscribeAdd(stream rpc.Config_DoConfigServer, req *rpc.ConfigRequest) {
fmt.Println("[sub]SubscribeAdd:", req.Module)

// In case of ribd we do a full resync from etcd - Delete and create
if IsRibdAsync(req.Module) {
RIBD_SYNCHRONIZED = true
} else {
fmt.Println("Lock:SubscribeAdd")
SubscribeMutex.Lock()
defer SubscribeMutex.Unlock()
}

sub := SubscribeLookup(stream)
if sub == nil {
sub = &Subscriber{Module: req.Module, Port: req.Port, stream: stream}
SubscribeMap[sub] = sub
}

// Registration
subPathList := []*SubPathRemote{}
for _, path := range req.Subscribe {
subPath := &SubPathRemote{sub: sub}
subPath.pathcmd = map[string][]*Command{}
subPath.sync = true
subPath.RegisterPath([]string{path.Path})
if path.Type == rpc.SubscribeType_JSON {
fmt.Println("XXX enable JSON", path.Path)
subPath.json = true
}
sub.SubPath = append(sub.SubPath, subPath)
subPathList = append(subPathList, subPath)
}

// Sync. Ribd needs special handling (order of resource configurations)
// So do a full etcd resync when ribd gets connected
if !IsRibdAsync(req.Module) {
SubscribeSync()
}

// Clear sync flag.
for _, subPath := range subPathList {
subPath.sync = false
}

if IsRibdAsync(req.Module) {
fmt.Println("Ribd connected. Perform full resync")
EtcdWatchUpdate()
}
//SubscribeDump()
}

func SubscribeRemoteAddMulti(stream rpc.Config_DoConfigServer, req *rpc.ConfigRequest) {
fmt.Println("[sub]SubscribeRemoteAddMulti:", req.Module)

Expand Down
2 changes: 2 additions & 0 deletions config/vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ func VrfParse(vrfId int, jsonStr string) {
VrrpVrfSync(vrfId, &vrf)
QuaggaVrfSync(vrfId, &vrf)
OspfVrfSync(vrfId, &vrf)
DistributeListSync(vrfId, &vrf)

// GoBGP VrfConfig
vrfConfig := vrf.Copy()
Expand All @@ -518,6 +519,7 @@ func VrfDelete(vrfId int, vrfIfDelete bool) {
VrrpVrfDelete(vrfId)
QuaggaVrfDelete(vrfId)
OspfVrfDelete(vrfId)
DistributeListDelete(vrfId)
EtcdVrfDelete(vrfId, vrfIfDelete)

delete(EtcdVrfMap, vrfId)
Expand Down
Loading

0 comments on commit 7e972b4

Please sign in to comment.