Пример #1
0
func addFlowEntriesForPath(sub bh.AppCellKey, path nom.Path,
	flows []nom.FlowEntry, ctx bh.RcvContext) {

	fs := make([]flowAndStatus, 0, len(flows))
	path.ID = strconv.FormatUint(reservePathID(ctx), 16)
	for i := range flows {
		flows[i].ID = path.ID
		fs = append(fs, flowAndStatus{Flow: flows[i]})
	}

	pf := pathAndFlows{
		Subscriber: sub,
		Path:       path,
		Flows:      fs,
		Timestamp:  time.Now(),
	}
	d := ctx.Dict(dictPath)
	if err := d.Put(path.ID, pf); err != nil {
		glog.Fatalf("error in storing path entry: %v", err)
	}

	ack := centralizedAppCellKey(ctx.App())
	for _, f := range flows {
		addf := nom.AddFlowEntry{
			Flow:       f,
			Subscriber: ack,
		}
		ctx.Emit(addf)
	}
}
Пример #2
0
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)
}