Skip to content

Commit

Permalink
Adapts to the latest Beehive API
Browse files Browse the repository at this point in the history
  • Loading branch information
soheilhy committed Jul 31, 2015
1 parent 340e02d commit 1c398a2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
18 changes: 15 additions & 3 deletions controller/consolidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,17 @@ type Poller struct{}

func (p Poller) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
dict := ctx.Dict(driversDict)
dict.ForEach(func(k string, v interface{}) {

var nds []nodeDrivers
dict.ForEach(func(k string, v interface{}) bool {
node := nom.UID(k)
query := nom.FlowStatsQuery{
Node: node,
}
sendToMaster(query, node, ctx)

nd := v.(nodeDrivers)
updated := false
for i := range nd.Drivers {
// TODO(soheil): remove the hardcoded value.
if nd.Drivers[i].OutPings > MaxPings {
Expand All @@ -109,12 +112,21 @@ func (p Poller) Rcv(msg bh.Msg, ctx bh.RcvContext) error {

ctx.SendToBee(nom.Ping{}, nd.Drivers[i].BeeID)
nd.Drivers[i].OutPings++
updated = true
}

if err := dict.Put(k, nd); err != nil {
glog.Warningf("error in encoding drivers: %v", err)
if updated {
nds = append(nds, nd)
}

return true
})

for _, nd := range nds {
if err := dict.Put(string(nd.Node.ID), nd); err != nil {
glog.Warningf("error in encoding drivers: %v", err)
}
}
return nil
}

Expand Down
17 changes: 11 additions & 6 deletions controller/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ func (h HealthChecker) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
db := msg.From()
dict := ctx.Dict(driversDict)

dict.ForEach(func(k string, v interface{}) {
var nds []nodeDrivers
dict.ForEach(func(k string, v interface{}) bool {
nd := v.(nodeDrivers)
updated := false
for i := range nd.Drivers {
Expand All @@ -27,15 +28,19 @@ func (h HealthChecker) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
}
}

if !updated {
return
if updated {
nds = append(nds, nd)
}

if err := dict.Put(k, nd); err != nil {
glog.Warningf("error in encoding drivers: %v", err)
}
return true

})

for _, nd := range nds {
if err := dict.Put(string(nd.Node.ID), nd); err != nil {
glog.Warningf("error in encoding drivers: %v", err)
}
}
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,12 @@ type timeoutHandler struct{}

func (h *timeoutHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
d := ctx.Dict(nodeDict)
d.ForEach(func(k string, v interface{}) {
d.ForEach(func(k string, v interface{}) bool {
np := v.(nodePortsAndLinks)
for _, p := range np.P {
sendLLDPPacket(np.N, p, ctx)
}
return true
})
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion discovery/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ func LinksCentralized(node nom.UID, ctx bh.RcvContext) (links []nom.Link) {
// Note that this methods should be used only when the GraphBuilderCentralized
// is in use.
func NodesCentralized(ctx bh.RcvContext) (nodes []nom.UID) {
ctx.Dict(GraphDict).ForEach(func(k string, v interface{}) {
ctx.Dict(GraphDict).ForEach(func(k string, v interface{}) bool {
nodes = append(nodes, nom.UID(k))
return true
})
return nodes
}
Expand Down
3 changes: 2 additions & 1 deletion kandoo/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ type Poller struct {
}

func (p Poller) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
ctx.Dict("Switches").ForEach(func(k string, v interface{}) {
ctx.Dict("Switches").ForEach(func(k string, v interface{}) bool {
fmt.Printf("poller: polling switch %v\n", k)
ctx.Emit(nom.FlowStatsQuery{
Node: nom.UID(k),
})
return true
})
return nil
}

0 comments on commit 1c398a2

Please sign in to comment.