/* Command simController is the controller end of a simulated dial-out switch configuration service. It is an upstream http://localhost:8080 server. It requires an NginX reverse proxy that presents its protocol as an HTTP2, mutual auth service on https://localcalhost:8443. NginX is expected to support switch configuration HTTP2 clients and multiplex their concurrent requests over a single TLS session. NginX will then spread client requests across one or more config servers. Each active request will be carried on a separate TCP connection. */ package main import ( "log" "net/http" "net/url" "time" ) const ( //The port this program presents its HTTP service on port = "8080" ) //handlePing is the http handler for /config requests func handlePing(w http.ResponseWriter, r *http.Request) { var ( pingQueryValues url.Values pingInterval string interval time.Duration err error ) //The interval query parameter specifies the number of seconds to delay responding to the ping. If none, ping is immediate. pingQueryValues, err = url.ParseQuery(r.URL.RawQuery) if err != nil { log.Printf("Ping request query string error: %s\n", err) w.WriteHeader(http.StatusBadRequest) return } pingInterval = pingQueryValues.Get("interval") if pingInterval == "" { log.Println("Responded immediately to Ping") return } else { interval, err = time.ParseDuration(pingInterval + "s") if err != nil { log.Printf("Ping interval conversion error: %s\n", err) w.WriteHeader(http.StatusBadRequest) return } time.Sleep(interval) log.Printf("Responded to Ping after %s seconds\n", pingInterval) } } //handlePing func main() { var ( err error ) //Start the simController service log.Printf("Starting the simController service on port %s", port) http.HandleFunc("/ping", handlePing) err = http.ListenAndServe(":"+port, nil) log.Printf("The simController service terminated with status: %s\n", err) }