Commit 188955d0 authored by M. Hamza's avatar M. Hamza
Browse files

update comments in mts.go

parent 49b71e39
Loading
Loading
Loading
Loading
+67 −72
Original line number Diff line number Diff line
@@ -432,12 +432,11 @@ func stopRegistrationTicker() {
	}
}

func storeMtsCapabilityInfoKey() (err error) {
/*
* storeMtsCapabilityInfoKey will create mtsCapabilityInfo body and save it in the redis DB in JSON format
* @return {error} err It returns error if error occurs in storing mtsCapabilityInfo in redis DB
 */

func storeMtsCapabilityInfoKey() (err error) {
	var mtsCapabilityInfo MtsCapabilityInfo
	//AccessType 1 refers to Any IEEE802.11-based WLAN technology
	accessInfo1 := MtsCapabilityInfoMtsAccessInfo{
@@ -477,6 +476,7 @@ func storeMtsCapabilityInfoKey() (err error) {
	return nil
}

// mtsCapabilityInfoGet is to retrieve mtsCapabilityInfo at /mts_capability_info endpoint
func mtsCapabilityInfoGet(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

@@ -502,8 +502,8 @@ func mtsCapabilityInfoGet(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, jsonResponse)
}

// mtsSessionDelete is to delete a specific mtsSessionInfo at /mts_sessions/{sessionId} endpoint
func mtsSessionDelete(w http.ResponseWriter, r *http.Request) {

	log.Info("Delete mtsSessionInfo by sessionId")

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
@@ -533,6 +533,7 @@ func mtsSessionDelete(w http.ResponseWriter, r *http.Request) {
	w.WriteHeader(http.StatusNoContent)
}

// mtsSessionGet is to retrieve a specific mtsSessionInfo at /mts_sessions/{sessionId} endpoint
func mtsSessionGet(w http.ResponseWriter, r *http.Request) {
	log.Info("Get individual mtsSessionInfo by sessionId")

@@ -565,6 +566,7 @@ func mtsSessionGet(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, jsonResponse)
}

// mtsSessionPost is to create mtsSessionInfo at /mts_sessions endpoint
func mtsSessionPost(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

@@ -623,11 +625,11 @@ func mtsSessionPost(w http.ResponseWriter, r *http.Request) {

	if *requestBody.RequestType == 1 && requestBody.FlowFilter != nil {
		sessionSlice := make([]MtsSessionInfoFlowFilter, 0)
		for index, singleSessionFilter := range requestBody.FlowFilter {
		for index, singleFlowFilter := range requestBody.FlowFilter {
			if index == 0 {
				sessionSlice = append(sessionSlice, singleSessionFilter)
				sessionSlice = append(sessionSlice, singleFlowFilter)
			} else {
				sessionSlice, err = sessionContains(sessionSlice, singleSessionFilter)
				sessionSlice, err = sessionContains(sessionSlice, singleFlowFilter)
				if err != nil {
					errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest)
					return
@@ -797,13 +799,12 @@ func compareFlowFilters(key string, jsonInfo string, flowFilterList interface{})
	return nil
}

func checkSrcIP(requestBody *MtsSessionInfo) (err error) {
/*
* checkSrcIP validate source ip range passed in CIDR notation with existing UE ip
* @param {*MtsSessionInfo} MTS session request body of POST method
* @return {error} err It returns err if the provided IP range is not valid against the existing UE IP (s)
 */

func checkSrcIP(requestBody *MtsSessionInfo) (err error) {
	ueNameList := activeModel.GetNodeNames("UE")
	// if the provided source IP range matches with the existing UE IP(s)
	if len(ueNameList) > 0 {
@@ -842,13 +843,12 @@ func checkSrcIP(requestBody *MtsSessionInfo) (err error) {
	return nil
}

func checkDstIP(requestBody *MtsSessionInfo) (err error) {
/*
* checkDstIP validate destination ip range passed in CIDR notation with existing UE IPs
* @param {*MtsSessionInfo} MTS session request body of POST method
* @return {error} err It returns err if the provided IP range is not valid against the existing UE IP (s)
 */

func checkDstIP(requestBody *MtsSessionInfo) (err error) {
	ueNameList := activeModel.GetNodeNames("UE")
	// if the provided destination IP range matches with the existing UE IP(s)
	if len(ueNameList) > 0 {
@@ -887,13 +887,12 @@ func checkDstIP(requestBody *MtsSessionInfo) (err error) {
	return nil
}

func isInLocality(name string) bool {
/*
* isInLocality validate UE ip only when they are in locality of current active model
* @param {string} name name(IP) of a UE
* @return {bool} bool It returns the locality status of UE present in the active model zone
 */

func isInLocality(name string) bool {
	if localityEnabled {
		ctx := activeModel.GetNodeContext(name)
		if ctx == nil {
@@ -907,13 +906,12 @@ func isInLocality(name string) bool {
	return true
}

func isUeConnected(name string) bool {
/*
* isUeConnected validate UE ip with connected UE(s) in the current active model
* @param {string} name name (IP) of a UE
* @return {bool} bool It returns the status of network connectivity of UE
 */

func isUeConnected(name string) bool {
	node := activeModel.GetNode(name)
	if node != nil {
		pl := node.(*dataModel.PhysicalLocation)
@@ -922,14 +920,13 @@ func isUeConnected(name string) bool {
	return false
}

func getAppInfo(appId string) (map[string]string, error) {
/*
* getAppInfo gets application information using its application Instance Id stored in redis
* @param {string} appId application Instance Id used to retrive its information from redis DB
*	@return {map[string]string} appInfo application information
* @return {error} err It returns error if there is no information associated with this appId
 */

func getAppInfo(appId string) (map[string]string, error) {
	var appInfo map[string]string

	// Get app instance from local MEP only
@@ -942,7 +939,6 @@ func getAppInfo(appId string) (map[string]string, error) {
	return appInfo, nil
}

func validateAppInfo(appInfo map[string]string) (int, string, error) {
/*
* validateAppInfo validates the status information of application to be in ready state
* @param {map[string]string} appInfo Information associated with application
@@ -950,7 +946,7 @@ func validateAppInfo(appInfo map[string]string) (int, string, error) {
* @return {string} string It returns the details of the problem if any
* @return {error} error It returns the error message for error if any otherwise nil
 */

func validateAppInfo(appInfo map[string]string) (int, string, error) {
	// Make sure App is in ready state
	if appInfo[fieldState] != APP_STATE_READY {
		var problemDetails ProblemDetails
@@ -961,6 +957,7 @@ func validateAppInfo(appInfo map[string]string) (int, string, error) {
	return http.StatusOK, "", nil
}

// mtsSessionPut updates the information about a specific mtsSessionInfo at /mts_sessions/{sessionId} endpoint
func mtsSessionPut(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	log.Info("mtsSessionPut Intializing")
@@ -1183,6 +1180,7 @@ func mtsSessionPut(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, jsonResponse)
}

// mtsSessionsListGet is to retrieve the information about all existing mtsSessionInfo at /mts_sessions endpoint
func mtsSessionsListGet(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

@@ -1239,7 +1237,6 @@ func mtsSessionsListGet(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, string(jsonResponse))
}

func populateMtsSessInfoList(key string, jsonInfo string, mtsSessionInfoList interface{}) error {
/**
* Function that list down all the MTS session(s) based on query parameters
* @param {string} key	MTS session stored with this key
@@ -1247,7 +1244,7 @@ func populateMtsSessInfoList(key string, jsonInfo string, mtsSessionInfoList int
* @param {*MtsSessInfoList} mtsSessionInfoList MTS session information
* @return {error} error An error will be return if occurs
 */

func populateMtsSessInfoList(key string, jsonInfo string, mtsSessionInfoList interface{}) error {
	// Get query params & mtsSessionInfo
	data := mtsSessionInfoList.(*MtsSessInfoList)
	if data == nil {
@@ -1303,13 +1300,12 @@ func populateMtsSessInfoList(key string, jsonInfo string, mtsSessionInfoList int
	return nil
}

func validateQueryParams(params url.Values, validParams []string) error {
/*
	* validateQueryParams ensures that valid query parameters should be used to retrieve one of the
		app_instance_id or app_name or session_id attributes from the user
	* @return {error} error An error will be return if occurs
*/

func validateQueryParams(params url.Values, validParams []string) error {
	for param := range params {
		found := false
		for _, validParam := range validParams {
@@ -1327,13 +1323,12 @@ func validateQueryParams(params url.Values, validParams []string) error {
	return nil
}

func validateMtsSesInfoQueryParams(appInstanceId []string, appName []string, sessionId []string) error {
/*
	* validateMtsSesInfoQueryParams check that either app_instance_id or app_name or session_id or
		none should be provided in the request
	* @return {error} error An error will be return if occurs
*/

func validateMtsSesInfoQueryParams(appInstanceId []string, appName []string, sessionId []string) error {
	count := 0
	if len(appInstanceId) != 0 {
		count++
@@ -1363,13 +1358,13 @@ func errHandlerProblemDetails(w http.ResponseWriter, error string, code int) {
	fmt.Fprint(w, jsonResponse)
}

func sessionContains(sessionSlice []MtsSessionInfoFlowFilter, singleSessionFilter MtsSessionInfoFlowFilter) ([]MtsSessionInfoFlowFilter, error) {
func sessionContains(sessionSlice []MtsSessionInfoFlowFilter, singleFlowFilter MtsSessionInfoFlowFilter) ([]MtsSessionInfoFlowFilter, error) {
	for _, sessionSlice1 := range sessionSlice {
		if reflect.DeepEqual(singleSessionFilter, sessionSlice1) {
			err := errors.New("SessionFilter contains duplicate sessions")
		if reflect.DeepEqual(singleFlowFilter, sessionSlice1) {
			err := errors.New("flowFilter contains duplicate sessions")
			return nil, err
		} else {
			sessionSlice = append(sessionSlice, singleSessionFilter)
			sessionSlice = append(sessionSlice, singleFlowFilter)
		}
	}
	return sessionSlice, nil