func (h *nodeLeftHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error { n := nom.Node(msg.Data().(nom.NodeLeft)) d := ctx.Dict(nodeDict) k := string(n.UID()) if _, err := d.Get(k); err != nil { return fmt.Errorf("%v is not joined", n) } d.Del(k) return nil }
func (h *nodeJoinedHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error { joined := msg.Data().(nom.NodeJoined) d := ctx.Dict(nodeDict) n := nom.Node(joined) k := string(n.UID()) var np nodePortsAndLinks if v, err := d.Get(k); err != nil { glog.Warningf("%v rejoins", n) } else { np = v.(nodePortsAndLinks) } np.N = n // Add a flow entry to forward arp packets to the controller mt := nom.Match{} mt.AddField(nom.EthType(nom.EthTypeARP)) acs := []nom.Action{ nom.ActionSendToController{ MaxLen: 0xffff, }, } fe := nom.FlowEntry{ ID: "Discovery-Host-ARP", Node: n.UID(), Priority: 0, Match: mt, Actions: acs, } afe := nom.AddFlowEntry{ Flow: fe, Subscriber: bh.AppCellKey{ App: ctx.App(), Key: k, Dict: nodeDict, }, } ctx.Emit(afe) // Add a flow entry to forward lldp packets to the controller mt = nom.Match{} mt.AddField(nom.EthType(nom.EthTypeLLDP)) acs = []nom.Action{ nom.ActionSendToController{ MaxLen: 0xffff, }, } fe = nom.FlowEntry{ ID: "Discovery-Topo-LLDP", Node: n.UID(), Priority: 0, Match: mt, Actions: acs, } afe = nom.AddFlowEntry{ Flow: fe, Subscriber: bh.AppCellKey{ App: ctx.App(), Key: k, Dict: nodeDict, }, } ctx.Emit(afe) return d.Put(k, np) }
func (h *nodeLeftHandler) Map(msg bh.Msg, ctx bh.MapContext) bh.MappedCells { return bh.MappedCells{ {nodeDict, string(nom.Node(msg.Data().(nom.NodeLeft)).UID())}, } }