diff --git a/build/images/Dockerfile.build.ubuntu b/build/images/Dockerfile.build.ubuntu index 32bc865a..3a3bfa50 100644 --- a/build/images/Dockerfile.build.ubuntu +++ b/build/images/Dockerfile.build.ubuntu @@ -1,4 +1,4 @@ -FROM ubuntu:20.04 +FROM registry.smtx.io/sdn-base/ubuntu:20.04 # Install golang diff --git a/ofctrl/ofctrl.go b/ofctrl/ofctrl.go index 92ff17f9..260e4289 100755 --- a/ofctrl/ofctrl.go +++ b/ofctrl/ofctrl.go @@ -80,6 +80,7 @@ type AppInterface interface { type Option func(opt *options) type Controller struct { + sw *OFSwitch app AppInterface listener *net.TCPListener wg sync.WaitGroup @@ -188,6 +189,11 @@ func (c *Controller) Connect(sock string) { continue } case <-c.exitCtx.Done(): + c.wg.Wait() + if c.sw != nil { + c.sw.Disconnect() + log.Println("switch disconnected") + } log.Println("Controller is delete") return } @@ -315,6 +321,7 @@ func (c *Controller) handleConnection(conn net.Conn) { reConnChan = c.connCh } s := NewSwitch(c.exitCtx, stream, m.DPID, c.app, reConnChan, c.controllerID, c.optionConfig.disableCleanGroup) + c.sw = s if err := s.switchConnected(); err != nil { log.Errorf("Failed to initialize OpenFlow switch %s: %v", m.DPID, err) // Do not send event "ReConnection" in "switchDisconnected", because the event is sent in