Esempio n. 1
0
func (p Poller) Rcv(msg bh.Msg, ctx bh.RcvContext) error {
	dict := ctx.Dict(driversDict)
	dict.ForEach(func(k string, v interface{}) {
		node := nom.UID(k)
		query := nom.FlowStatsQuery{
			Node: node,
		}
		sendToMaster(query, node, ctx)

		nd := v.(nodeDrivers)
		for i := range nd.Drivers {
			// TODO(soheil): remove the hardcoded value.
			if nd.Drivers[i].OutPings > MaxPings {
				ctx.SendToBee(nom.NodeDisconnected{
					Node:   nom.Node{ID: nom.NodeID(node)},
					Driver: nd.Drivers[i].Driver,
				}, ctx.ID())
				continue
			}

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

		if err := dict.Put(k, nd); err != nil {
			glog.Warningf("error in encoding drivers: %v", err)
		}
	})
	return nil
}
Esempio n. 2
0
func (c *ofConn) handshake() (ofDriver, error) {
	hdr, err := c.ReadHeader()
	if err != nil {
		return nil, err
	}

	h, err := of.ToHello(hdr)
	if err != nil {
		return nil, err
	}

	glog.V(2).Info("%v received hello from a switch with OFv%v", c.ctx,
		h.Version())

	version := of.OPENFLOW_1_0
	if h.Version() >= uint8(of.OPENFLOW_1_2) {
		version = of.OPENFLOW_1_2
	}
	h.SetVersion(uint8(version))

	if err = c.WriteHeader(h.Header); err != nil {
		return nil, err
	}
	c.Flush()

	glog.V(2).Info("%v sent hello to the switch", c.ctx)

	var driver ofDriver
	switch version {
	case of.OPENFLOW_1_0:
		driver = &of10Driver{}
	case of.OPENFLOW_1_2:
		driver = &of12Driver{}
	}

	if err = driver.handshake(c); err != nil {
		return nil, err
	}

	if c.node.ID == nom.NodeID(0) {
		return nil, errors.New("ofConn: invalid node after handshake")
	}

	return driver, nil
}
Esempio n. 3
0
func datapathIDToNodeID(dpID uint64) nom.NodeID {
	return nom.NodeID(strconv.FormatUint(dpID, 16))
}