Example #1
0
// Sends an OpenFlow message to s, and returns a channel to receive
// a response on. Any error encountered during the send except io.EOF
// is returned.
func (s *OFSwitch) SendAndReceive(msg ofp10.Packet) chan ofp10.Msg {
	ch := make(chan ofp10.Msg)
	s.reqsMu.Lock()
	s.reqs[msg.GetHeader().XID] = ch
	s.reqsMu.Unlock()

	s.Send(msg)
	return ch
}
Example #2
0
func (s *OFSwitch) distributeMessages(dpid net.HardwareAddr, msg ofp10.Packet) {
	header := msg.GetHeader()

	s.reqsMu.RLock()
	if ch, ok := s.reqs[header.XID]; ok {
		m := ofp10.Msg{msg, dpid}
		ch <- m
		delete(s.reqs, header.XID)
	} else {
		switch t := msg.(type) {
		case *ofp10.SwitchFeatures:
			for _, app := range s.appInstance {
				if actor, ok := app.(ofp10.SwitchFeaturesReactor); ok {
					actor.FeaturesReply(s.DPID(), t)
				}
			}
		case *ofp10.PacketIn:
			for _, app := range s.appInstance {
				if actor, ok := app.(ofp10.PacketInReactor); ok {
					actor.PacketIn(s.DPID(), t)
				}
			}
		case *ofp10.Header:
			switch t.GetHeader().Type {
			case ofp10.T_ECHO_REPLY:
				for _, app := range s.appInstance {
					if actor, ok := app.(ofp10.EchoReplyReactor); ok {
						actor.EchoReply(s.DPID())
					}
				}
			case ofp10.T_ECHO_REQUEST:
				for _, app := range s.appInstance {
					if actor, ok := app.(ofp10.EchoRequestReactor); ok {
						actor.EchoRequest(s.DPID())
					}
				}
			}
		}
	}
	s.reqsMu.RUnlock()
}
Example #3
0
func (m *MessageStream) parse(buf []byte) {
	var d ofp10.Packet
	switch buf[1] {
	case ofp10.T_PACKET_IN:
		d = new(ofp10.PacketIn)
		d.Write(buf)
	case ofp10.T_HELLO:
		d = new(ofp10.Header)
		d.Write(buf)
	case ofp10.T_ECHO_REPLY:
		d = new(ofp10.Header)
		d.Write(buf)
	case ofp10.T_ECHO_REQUEST:
		d = new(ofp10.Header)
		d.Write(buf)
	case ofp10.T_ERROR:
		d = new(ofp10.ErrorMsg)
		d.Write(buf)
	case ofp10.T_VENDOR:
		d = new(ofp10.VendorHeader)
		d.Write(buf)
	case ofp10.T_FEATURES_REPLY:
		d = new(ofp10.SwitchFeatures)
		d.Write(buf)
	case ofp10.T_GET_CONFIG_REPLY:
		d = new(ofp10.SwitchConfig)
		d.Write(buf)
	case ofp10.T_FLOW_REMOVED:
		d = new(ofp10.FlowRemoved)
		d.Write(buf)
	case ofp10.T_PORT_STATUS:
		d = new(ofp10.PortStatus)
		d.Write(buf)
	case ofp10.T_STATS_REPLY:
		d = new(ofp10.StatsReply)
		d.Write(buf)
	case ofp10.T_BARRIER_REPLY:
		d = new(ofp10.Header)
		d.Write(buf)
	default:
		// Unrecognized packet do nothing
	}
	m.Inbound <- d
}