Commit a21a3a01 authored by muhammadh's avatar muhammadh
Browse files

revert WebSock implementation for now and add validation checks

parent bd7a3875
Loading
Loading
Loading
Loading
+40 −204
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import (
	smc "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-service-mgmt-client"

	"github.com/gorilla/mux"
	"github.com/gorilla/websocket"
)

const moduleName = "meep-rnis"
@@ -1616,11 +1615,11 @@ func checkCcNotificationRegisteredSubscriptions(appId string, assocId *Associate
				}

				if subscription.CallbackReference != "" {
					sendCcNotification(subscription.CallbackReference, notif, false)
					log.Info("Cell_change Notification" + "(" + subsIdStr + ")")
				} else {
					sendCcNotification(subscription.WebsockNotifConfig.WebsocketUri, notif, true)
					sendCcNotification(subscription.CallbackReference, notif)
					log.Info("Cell_change Notification" + "(" + subsIdStr + ")")
				} else if subscription.WebsockNotifConfig.RequestWebsocketUri != false {
					log.Error("WebSocket functionality is not implemented currently")
					return
				}
			}
		}
@@ -1699,11 +1698,11 @@ func checkReNotificationRegisteredSubscriptions(appId string, assocId *Associate
				}

				if subscription.CallbackReference != "" {
					sendReNotification(subscription.CallbackReference, notif, false)
					log.Info("Rab_establishment Notification" + "(" + subsIdStr + ")")
				} else {
					sendReNotification(subscription.WebsockNotifConfig.WebsocketUri, notif, true)
					sendReNotification(subscription.CallbackReference, notif)
					log.Info("Rab_establishment Notification" + "(" + subsIdStr + ")")
				} else if subscription.WebsockNotifConfig.RequestWebsocketUri != false {
					log.Error("WebSocket functionality is not implemented currently")
					return
				}
			}
		}
@@ -1783,11 +1782,11 @@ func checkRrNotificationRegisteredSubscriptions(appId string, assocId *Associate
				}

				if subscription.CallbackReference != "" {
					sendRrNotification(subscription.CallbackReference, notif, false)
					log.Info("Rab_release Notification" + "(" + subsIdStr + ")")
				} else {
					sendRrNotification(subscription.WebsockNotifConfig.WebsocketUri, notif, true)
					sendRrNotification(subscription.CallbackReference, notif)
					log.Info("Rab_release Notification" + "(" + subsIdStr + ")")
				} else if subscription.WebsockNotifConfig.RequestWebsocketUri != false {
					log.Error("WebSocket functionality is not implemented currently")
					return
				}
			}
		}
@@ -1918,11 +1917,12 @@ func checkMrNotificationRegisteredSubscriptions(key string, jsonInfo string, ext
				if parentMeasExists {
					if subscription.CallbackReference != "" {
						log.Info("Sending RNIS notification ", subscription.CallbackReference)
						go sendMrNotification(subscription.CallbackReference, notif, false)
						log.Info("Meas_Rep_Ue Notification" + "(" + subsIdStr + ")")
					} else {
						go sendMrNotification(subscription.WebsockNotifConfig.WebsocketUri, notif, true)
						go sendMrNotification(subscription.CallbackReference, notif)
						log.Info("Meas_Rep_Ue Notification" + "(" + subsIdStr + ")")
					} else if subscription.WebsockNotifConfig.RequestWebsocketUri != false {
						log.Error("WebSocket functionality is not implemented currently")
						err = errors.New("WebSocket functionality is not implemented currently")
						return err
					}
				}
			}
@@ -2080,11 +2080,12 @@ func checkNrMrNotificationRegisteredSubscriptions(key string, jsonInfo string, e
				if parentMeasExists {
					if subscription.CallbackReference != "" {
						log.Info("Sending RNIS notification ", subscription.CallbackReference)
						go sendNrMrNotification(subscription.CallbackReference, notif, false)
						log.Info("Nr_Meas_Rep_Ue Notification" + "(" + subsIdStr + ")")
					} else {
						go sendNrMrNotification(subscription.WebsockNotifConfig.WebsocketUri, notif, true)
						go sendNrMrNotification(subscription.CallbackReference, notif)
						log.Info("Nr_Meas_Rep_Ue Notification" + "(" + subsIdStr + ")")
					} else if subscription.WebsockNotifConfig.RequestWebsocketUri != false {
						log.Error("WebSocket functionality is not implemented currently")
						err = errors.New("WebSocket functionality is not implemented currently")
						return err
					}
				}
			}
@@ -2093,263 +2094,98 @@ func checkNrMrNotificationRegisteredSubscriptions(key string, jsonInfo string, e
	return nil
}

func sendCcNotification(notifyUrl string, notification CellChangeNotification, isWebsocket bool) {
func sendCcNotification(notifyUrl string, notification CellChangeNotification) {
	startTime := time.Now()
	jsonNotif, err := json.Marshal(notification)
	if err != nil {
		log.Error(err.Error())
	}

	var resp *http.Response
	var c *websocket.Conn

	switch isWebsocket {
	case true:
		c, _, err = websocket.DefaultDialer.Dial(notifyUrl, nil)
		if err != nil {
			log.Error(err.Error())
			break
		}

		// send message
		err = c.WriteMessage(websocket.TextMessage, []byte(jsonNotif))
		if err != nil {
			// handle error
			log.Error(err.Error())
			break
		}

		// receive message
		_, _, err = c.ReadMessage()
		if err != nil {
			log.Error(err.Error())
			break
		}

		resp = &http.Response{
			StatusCode: http.StatusNoContent,
		}
	case false:
		resp, err = http.Post(notifyUrl, "application/json", bytes.NewBuffer(jsonNotif))
		_ = httpLog.LogTx(notifyUrl, "POST", string(jsonNotif), resp, startTime)
	}

	resp, err := http.Post(notifyUrl, "application/json", bytes.NewBuffer(jsonNotif))
	duration := float64(time.Since(startTime).Microseconds()) / 1000.0
	_ = httpLog.LogTx(notifyUrl, "POST", string(jsonNotif), resp, startTime)
	if err != nil {
		log.Error(err)
		met.ObserveNotification(sandboxName, serviceName, notifCellChange, notifyUrl, nil, duration)
		return
	}
	met.ObserveNotification(sandboxName, serviceName, notifCellChange, notifyUrl, resp, duration)
	defer c.Close()
	defer resp.Body.Close()
}

func sendReNotification(notifyUrl string, notification RabEstNotification, isWebsocket bool) {
func sendReNotification(notifyUrl string, notification RabEstNotification) {
	startTime := time.Now()
	jsonNotif, err := json.Marshal(notification)
	if err != nil {
		log.Error(err.Error())
	}

	var resp *http.Response
	var c *websocket.Conn

	switch isWebsocket {
	case true:
		c, _, err = websocket.DefaultDialer.Dial(notifyUrl, nil)
		if err != nil {
			log.Error(err.Error())
			break
		}

		// send message
		err = c.WriteMessage(websocket.TextMessage, []byte(jsonNotif))
		if err != nil {
			// handle error
			log.Error(err.Error())
			break
		}

		// receive message
		_, _, err = c.ReadMessage()
		if err != nil {
			log.Error(err.Error())
			break
		}

		resp = &http.Response{
			StatusCode: http.StatusNoContent,
		}
	case false:
		resp, err = http.Post(notifyUrl, "application/json", bytes.NewBuffer(jsonNotif))
		_ = httpLog.LogTx(notifyUrl, "POST", string(jsonNotif), resp, startTime)
	}

	resp, err := http.Post(notifyUrl, "application/json", bytes.NewBuffer(jsonNotif))
	duration := float64(time.Since(startTime).Microseconds()) / 1000.0
	_ = httpLog.LogTx(notifyUrl, "POST", string(jsonNotif), resp, startTime)
	if err != nil {
		log.Error(err)
		met.ObserveNotification(sandboxName, serviceName, notifRabEst, notifyUrl, nil, duration)
		return
	}
	met.ObserveNotification(sandboxName, serviceName, notifRabEst, notifyUrl, resp, duration)
	defer c.Close()
	defer resp.Body.Close()
}

func sendRrNotification(notifyUrl string, notification RabRelNotification, isWebsocket bool) {
func sendRrNotification(notifyUrl string, notification RabRelNotification) {
	startTime := time.Now()
	jsonNotif, err := json.Marshal(notification)
	if err != nil {
		log.Error(err.Error())
	}

	var resp *http.Response
	var c *websocket.Conn

	switch isWebsocket {
	case true:
		c, _, err = websocket.DefaultDialer.Dial(notifyUrl, nil)
		if err != nil {
			log.Error(err.Error())
			break
		}

		// send message
		err = c.WriteMessage(websocket.TextMessage, []byte(jsonNotif))
		if err != nil {
			// handle error
			log.Error(err.Error())
			break
		}

		// receive message
		_, _, err = c.ReadMessage()
		if err != nil {
			log.Error(err.Error())
			break
		}

		resp = &http.Response{
			StatusCode: http.StatusNoContent,
		}
	case false:
		resp, err = http.Post(notifyUrl, "application/json", bytes.NewBuffer(jsonNotif))
		_ = httpLog.LogTx(notifyUrl, "POST", string(jsonNotif), resp, startTime)
	}

	resp, err := http.Post(notifyUrl, "application/json", bytes.NewBuffer(jsonNotif))
	duration := float64(time.Since(startTime).Microseconds()) / 1000.0
	_ = httpLog.LogTx(notifyUrl, "POST", string(jsonNotif), resp, startTime)
	if err != nil {
		log.Error(err)
		met.ObserveNotification(sandboxName, serviceName, notifRabRel, notifyUrl, nil, duration)
		return
	}
	met.ObserveNotification(sandboxName, serviceName, notifRabRel, notifyUrl, resp, duration)
	defer c.Close()
	defer resp.Body.Close()
}

func sendMrNotification(notifyUrl string, notification MeasRepUeNotification, isWebsocket bool) {
func sendMrNotification(notifyUrl string, notification MeasRepUeNotification) {
	startTime := time.Now()
	jsonNotif, err := json.Marshal(notification)
	if err != nil {
		log.Error(err.Error())
	}

	var resp *http.Response
	var c *websocket.Conn

	switch isWebsocket {
	case true:
		c, _, err = websocket.DefaultDialer.Dial(notifyUrl, nil)
		if err != nil {
			log.Error(err.Error())
			break
		}

		// send message
		err = c.WriteMessage(websocket.TextMessage, []byte(jsonNotif))
		if err != nil {
			// handle error
			log.Error(err.Error())
			break
		}

		// receive message
		_, _, err = c.ReadMessage()
		if err != nil {
			log.Error(err.Error())
			break
		}

		resp = &http.Response{
			StatusCode: http.StatusNoContent,
		}
	case false:
		resp, err = http.Post(notifyUrl, "application/json", bytes.NewBuffer(jsonNotif))
		_ = httpLog.LogTx(notifyUrl, "POST", string(jsonNotif), resp, startTime)
	}

	resp, err := http.Post(notifyUrl, "application/json", bytes.NewBuffer(jsonNotif))
	duration := float64(time.Since(startTime).Microseconds()) / 1000.0
	_ = httpLog.LogTx(notifyUrl, "POST", string(jsonNotif), resp, startTime)
	if err != nil {
		log.Error(err)
		met.ObserveNotification(sandboxName, serviceName, notifMeasRepUe, notifyUrl, nil, duration)
		return
	}
	met.ObserveNotification(sandboxName, serviceName, notifMeasRepUe, notifyUrl, resp, duration)
	defer c.Close()
	defer resp.Body.Close()
}

func sendNrMrNotification(notifyUrl string, notification NrMeasRepUeNotification, isWebsocket bool) {
func sendNrMrNotification(notifyUrl string, notification NrMeasRepUeNotification) {
	startTime := time.Now()
	jsonNotif, err := json.Marshal(notification)
	if err != nil {
		log.Error(err.Error())
	}

	var resp *http.Response
	var c *websocket.Conn

	switch isWebsocket {
	case true:
		c, _, err = websocket.DefaultDialer.Dial(notifyUrl, nil)
		if err != nil {
			log.Error(err.Error())
			break
		}

		// send message
		err = c.WriteMessage(websocket.TextMessage, []byte(jsonNotif))
		if err != nil {
			// handle error
			log.Error(err.Error())
			break
		}

		// receive message
		_, _, err = c.ReadMessage()
		if err != nil {
			log.Error(err.Error())
			break
		}

		resp = &http.Response{
			StatusCode: http.StatusNoContent,
		}
	case false:
		resp, err = http.Post(notifyUrl, "application/json", bytes.NewBuffer(jsonNotif))
		_ = httpLog.LogTx(notifyUrl, "POST", string(jsonNotif), resp, startTime)
	}

	resp, err := http.Post(notifyUrl, "application/json", bytes.NewBuffer(jsonNotif))
	duration := float64(time.Since(startTime).Microseconds()) / 1000.0
	_ = httpLog.LogTx(notifyUrl, "POST", string(jsonNotif), resp, startTime)
	if err != nil {
		log.Error(err)
		met.ObserveNotification(sandboxName, serviceName, notifNrMeasRepUe, notifyUrl, nil, duration)
		return
	}
	met.ObserveNotification(sandboxName, serviceName, notifNrMeasRepUe, notifyUrl, resp, duration)
	defer c.Close()
	defer resp.Body.Close()
}

@@ -2481,9 +2317,9 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) {
	subscriptionType := subscriptionCommon.SubscriptionType

	//mandatory parameter
	if subscriptionCommon.CallbackReference == "" && subscriptionCommon.WebsockNotifConfig.WebsocketUri == "" {
		log.Error("At least one of the attributes CallbackReference or WebsockNotifConfig should be present")
		http.Error(w, "At least one of the attributes CallbackReference or WebsockNotifConfig should be present", http.StatusBadRequest)
	if subscriptionCommon.CallbackReference == "" {
		log.Error("Mandatory CallbackReference parameter not present")
		http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest)
		return
	}