Beispiel #1
0
func (b GraphBuilderCentralized) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
	dict := ctx.Dict(GraphDict)
	var link nom.Link
	switch dm := msg.Data().(type) {
	case nom.LinkAdded:
		link = nom.Link(dm)
	case nom.LinkDeleted:
		link = nom.Link(dm)
	default:
		return fmt.Errorf("GraphBuilderCentralized: unsupported message type %v",
			msg.Type())
	}

	nf, _ := nom.ParsePortUID(link.From)
	nt, _ := nom.ParsePortUID(link.To)

	if nf == nt {
		return fmt.Errorf("%v is a loop", link)
	}

	k := string(nf)
	links := make(map[nom.UID][]nom.Link)
	if v, err := dict.Get(k); err == nil {
		links = v.(map[nom.UID][]nom.Link)
	}
	links[nt.UID()] = append(links[nt.UID()], link)
	return dict.Put(k, links)
}
Beispiel #2
0
func (h flowHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
	switch data := msg.Data().(type) {
	case nom.FlowEntryAdded:
		return confirmFlowEntryForPath(nom.FlowEntry(data.Flow), ctx)
	case nom.FlowEntryDeleted:
		return delFlowEntryFromPath(nom.FlowEntry(data.Flow), ctx)
	}
	return fmt.Errorf("flowHandler: unsupported message %v", msg.Type())
}