func (d *of12Driver) handlePkt(pkt of.Header, c *ofConn) error { pkt12, err := of12.ToHeader12(pkt) if err != nil { return err } switch { case of12.IsEchoRequest(pkt12): return d.handleEchoRequest(of12.NewEchoRequestWithBuf(pkt12.Buf), c) case of12.IsFeaturesReply(pkt12): return d.handleFeaturesReply(of12.NewFeaturesReplyWithBuf(pkt12.Buf), c) case of12.IsPacketIn(pkt12): return d.handlePacketIn(of12.NewPacketInWithBuf(pkt12.Buf), c) case of12.IsErrorMsg(pkt12): return d.handleErrorMsg(of12.NewErrorMsgWithBuf(pkt12.Buf), c) case of12.IsStatsReply(pkt12): return d.handleStatsReply(of12.NewStatsReplyWithBuf(pkt12.Buf), c) case of12.IsRoleReply(pkt12): return d.handleRoleReply(of12.NewRoleReplyWithBuf(pkt12.Buf), c) case of12.IsPortStatus(pkt12): return d.handlePortStatus(of12.NewPortStatusWithBuf(pkt12.Buf), c) default: return fmt.Errorf("received unsupported packet: %v", pkt.Type()) } }
func doHandleEchoRequest(req of.Header, res of.Header, c *ofConn) error { glog.V(2).Infof("Received echo request from %v", c.node) res.SetXid(req.Xid()) err := c.WriteHeaders([]of.Header{res}) if err != nil { return err } c.Flush() glog.V(2).Infof("Sent echo reply to %v", c.node) return nil }