From 1905af8509209f5f21463f5e86acda66d0bf185b Mon Sep 17 00:00:00 2001 From: Wenying Dong Date: Thu, 29 Jun 2023 10:24:31 -0700 Subject: [PATCH] Remove flowMonitor key after the MultipartReply is received (#64) After "monitorEnabled" is enabled, an OpenFlow FlowDesc message is sent to dump the flow stats if a user calls OFSwitch.DumpFlowStats or Flow.MonitorRealizeStatus. At this time the message's transactionsID is added into a concurrent map monitoredFlows. The issue is the transactionID is not removed after the reply of FlowDesc message is received. This change is to fix the issue. Signed-off-by: wenyingd --- VERSION | 2 +- ofctrl/ofSwitch.go | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/VERSION b/VERSION index b19b5211..85f7059b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v0.8.0 +v0.8.1 diff --git a/ofctrl/ofSwitch.go b/ofctrl/ofSwitch.go index 63dbdcb6..4da4a0d9 100755 --- a/ofctrl/ofSwitch.go +++ b/ofctrl/ofSwitch.go @@ -339,16 +339,19 @@ func (self *OFSwitch) handleMessages(dpid net.HardwareAddr, msg util.Message) { case *openflow15.MultipartReply: log.Debugf("Received MultipartReply") - rep := (*openflow15.MultipartReply)(t) - if self.monitorEnabled { - key := fmt.Sprintf("%d", rep.Xid) + switch t.Type { + case openflow15.MultipartType_FlowDesc: + key := fmt.Sprintf("%d", t.Xid) replyChan, found := monitoredFlows.Get(key) if found { - replyChan <- rep + if self.monitorEnabled { + replyChan <- t + } + monitoredFlows.Remove(key) } } // send packet rcvd callback - self.app.MultipartReply(self, rep) + self.app.MultipartReply(self, t) case *openflow15.VendorError: errData := t.ErrorMsg.Data.Bytes() result := MessageResult{ @@ -437,18 +440,14 @@ func (self *OFSwitch) DumpFlowStats(cookieID uint64, cookieMask *uint64, flowMat select { case reply := <-replyChan: flowStates := make([]*openflow15.FlowDesc, 0) - if reply.Type == openflow15.MultipartType_FlowDesc { - flowArr := reply.Body - for _, entry := range flowArr { - flowStates = append(flowStates, entry.(*openflow15.FlowDesc)) - } - return flowStates, nil + flowArr := reply.Body + for _, entry := range flowArr { + flowStates = append(flowStates, entry.(*openflow15.FlowDesc)) } - + return flowStates, nil case <-time.After(2 * time.Second): return nil, errors.New("timeout to wait for MultipartReply message") } - return nil, nil } func (self *OFSwitch) CheckStatus(timeout time.Duration) bool {