Loading go-apps/meep-tm/server/bwm/bwm.go +119 −106 Original line number Diff line number Diff line Loading @@ -949,6 +949,8 @@ func bandwidthAllocationPost(w http.ResponseWriter, r *http.Request) { return } } } else if *bwInfo.RequestType == 0 { bwInfo.SessionFilter = nil } if *bwInfo.RequestType == 1 && bwInfo.SessionFilter != nil { Loading Loading @@ -1058,114 +1060,11 @@ func bandwidthAllocationPost(w http.ResponseWriter, r *http.Request) { // In APPLICATION_SPECIFIC_BW_ALLOCATION OR SESSION_SPECIFIC_BW_ALLOCATION // Uplink, Downlink and Symmetrical bandwidth allocation is performed switch bwInfo.AllocationDirection { case "00": // getting downlink buffer value from redis to update bufferInfo, valBuff, err := getDownlinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return } // To start allocating resource, buffer value should be non-zero if valBuff > 0 { var valFixedBuff uint64 valFixedBuff, err = strconv.ParseUint(bwInfo.FixedAllocation, 10, 64) // The value of resource needed to be allocate should also be no-zero if (valFixedBuff > 0) && (err == nil) { newAllocId := nextBwAllocIdAvailable bwInfo.AllocationId = strconv.FormatUint(uint64(newAllocId), 10) bufferInfo["down"] = strconv.FormatUint(valBuff-valFixedBuff, 10) // updateBuffer function takes updated buffer Information and store it in redis // returns error if unable to store allocation buffer in redis err = updateBuffer(bufferInfo) if bwInfo.AllocationDirection != "" { err = bandwidthResourceAllocation(bwInfo, w) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } else { log.Info("Allocation downlink buffer is updated") } nextBwAllocIdAvailable++ // increment allocation ID } } else { log.Debug("Resources are insufficient for this allocation") } case "01": // getting uplink buffer value from redis to update bufferInfo, valBuff, err := getUplinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return } // To start allocating resource, buffer value should be non-zero if valBuff > 0 { var valFixedBuff uint64 valFixedBuff, err = strconv.ParseUint(bwInfo.FixedAllocation, 10, 64) // The value of resource needed to be allocate should also be no-zero if (valFixedBuff > 0) && (err == nil) { newAllocId := nextBwAllocIdAvailable bwInfo.AllocationId = strconv.FormatUint(uint64(newAllocId), 10) bufferInfo["up"] = strconv.FormatUint(valBuff-valFixedBuff, 10) // updateBuffer function takes updated buffer Information and store it in redis // returns error if unable to store allocation buffer in redis err = updateBuffer(bufferInfo) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } else { log.Info("Allocation uplink buffer is updated") } nextBwAllocIdAvailable++ } } else { log.Debug("Resources are insufficient for this allocation") } case "10": // getting downlink/uplink buffer value from redis to update _, valBuffup, err := getUplinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return } bufferInfo, valBuffdown, err := getDownlinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return } // To start allocating resource, buffer values should be non-zero if (valBuffup > 0) && (valBuffdown > 0) { var valFixedBuff uint64 valFixedBuff, err = strconv.ParseUint(bwInfo.FixedAllocation, 10, 64) // The value of resource needed to be allocate should also be no-zero if (valFixedBuff > 0) && (err == nil) { newAllocId := nextBwAllocIdAvailable bwInfo.AllocationId = strconv.FormatUint(uint64(newAllocId), 10) bufferInfo["up"] = strconv.FormatUint(valBuffup-(valFixedBuff/2), 10) bufferInfo["down"] = strconv.FormatUint(valBuffdown-(valFixedBuff/2), 10) // updateBuffer function takes updated buffer Information and store it in redis // returns error if unable to store allocation buffer in redis err = updateBuffer(bufferInfo) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } else { log.Info("Allocation downlink buffer is updated") } nextBwAllocIdAvailable++ } } else { log.Debug("Resources are insufficient for this allocation") } } // setBwInfo function takes input of new BW allocation information and Loading Loading @@ -2096,3 +1995,117 @@ func compareSessionFilters(key string, jsonInfo string, sessionFilterList interf } return nil } func bandwidthResourceAllocation(bwInfo BwInfo, w http.ResponseWriter) error { switch bwInfo.AllocationDirection { case "00": // getting downlink buffer value from redis to update bufferInfo, valBuff, err := getDownlinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return err } // To start allocating resource, buffer value should be non-zero if valBuff > 0 { var valFixedBuff uint64 valFixedBuff, err = strconv.ParseUint(bwInfo.FixedAllocation, 10, 64) // The value of resource needed to be allocate should also be no-zero if (valFixedBuff > 0) && (err == nil) { newAllocId := nextBwAllocIdAvailable bwInfo.AllocationId = strconv.FormatUint(uint64(newAllocId), 10) bufferInfo["down"] = strconv.FormatUint(valBuff-valFixedBuff, 10) // updateBuffer function takes updated buffer Information and store it in redis // returns error if unable to store allocation buffer in redis err = updateBuffer(bufferInfo) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return err } else { log.Info("Allocation downlink buffer is updated") } nextBwAllocIdAvailable++ // increment allocation ID } } else { log.Debug("Resources are insufficient for this allocation") } case "01": // getting uplink buffer value from redis to update bufferInfo, valBuff, err := getUplinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return err } // To start allocating resource, buffer value should be non-zero if valBuff > 0 { var valFixedBuff uint64 valFixedBuff, err = strconv.ParseUint(bwInfo.FixedAllocation, 10, 64) // The value of resource needed to be allocate should also be no-zero if (valFixedBuff > 0) && (err == nil) { newAllocId := nextBwAllocIdAvailable bwInfo.AllocationId = strconv.FormatUint(uint64(newAllocId), 10) bufferInfo["up"] = strconv.FormatUint(valBuff-valFixedBuff, 10) // updateBuffer function takes updated buffer Information and store it in redis // returns error if unable to store allocation buffer in redis err = updateBuffer(bufferInfo) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return err } else { log.Info("Allocation uplink buffer is updated") } nextBwAllocIdAvailable++ } } else { log.Debug("Resources are insufficient for this allocation") } case "10": // getting downlink/uplink buffer value from redis to update _, valBuffup, err := getUplinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return err } bufferInfo, valBuffdown, err := getDownlinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return err } // To start allocating resource, buffer values should be non-zero if (valBuffup > 0) && (valBuffdown > 0) { var valFixedBuff uint64 valFixedBuff, err = strconv.ParseUint(bwInfo.FixedAllocation, 10, 64) // The value of resource needed to be allocate should also be no-zero if (valFixedBuff > 0) && (err == nil) { newAllocId := nextBwAllocIdAvailable bwInfo.AllocationId = strconv.FormatUint(uint64(newAllocId), 10) bufferInfo["up"] = strconv.FormatUint(valBuffup-(valFixedBuff/2), 10) bufferInfo["down"] = strconv.FormatUint(valBuffdown-(valFixedBuff/2), 10) // updateBuffer function takes updated buffer Information and store it in redis // returns error if unable to store allocation buffer in redis err = updateBuffer(bufferInfo) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return err } else { log.Info("Allocation downlink buffer is updated") } nextBwAllocIdAvailable++ } } else { log.Debug("Resources are insufficient for this allocation") } } return nil } Loading
go-apps/meep-tm/server/bwm/bwm.go +119 −106 Original line number Diff line number Diff line Loading @@ -949,6 +949,8 @@ func bandwidthAllocationPost(w http.ResponseWriter, r *http.Request) { return } } } else if *bwInfo.RequestType == 0 { bwInfo.SessionFilter = nil } if *bwInfo.RequestType == 1 && bwInfo.SessionFilter != nil { Loading Loading @@ -1058,114 +1060,11 @@ func bandwidthAllocationPost(w http.ResponseWriter, r *http.Request) { // In APPLICATION_SPECIFIC_BW_ALLOCATION OR SESSION_SPECIFIC_BW_ALLOCATION // Uplink, Downlink and Symmetrical bandwidth allocation is performed switch bwInfo.AllocationDirection { case "00": // getting downlink buffer value from redis to update bufferInfo, valBuff, err := getDownlinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return } // To start allocating resource, buffer value should be non-zero if valBuff > 0 { var valFixedBuff uint64 valFixedBuff, err = strconv.ParseUint(bwInfo.FixedAllocation, 10, 64) // The value of resource needed to be allocate should also be no-zero if (valFixedBuff > 0) && (err == nil) { newAllocId := nextBwAllocIdAvailable bwInfo.AllocationId = strconv.FormatUint(uint64(newAllocId), 10) bufferInfo["down"] = strconv.FormatUint(valBuff-valFixedBuff, 10) // updateBuffer function takes updated buffer Information and store it in redis // returns error if unable to store allocation buffer in redis err = updateBuffer(bufferInfo) if bwInfo.AllocationDirection != "" { err = bandwidthResourceAllocation(bwInfo, w) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } else { log.Info("Allocation downlink buffer is updated") } nextBwAllocIdAvailable++ // increment allocation ID } } else { log.Debug("Resources are insufficient for this allocation") } case "01": // getting uplink buffer value from redis to update bufferInfo, valBuff, err := getUplinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return } // To start allocating resource, buffer value should be non-zero if valBuff > 0 { var valFixedBuff uint64 valFixedBuff, err = strconv.ParseUint(bwInfo.FixedAllocation, 10, 64) // The value of resource needed to be allocate should also be no-zero if (valFixedBuff > 0) && (err == nil) { newAllocId := nextBwAllocIdAvailable bwInfo.AllocationId = strconv.FormatUint(uint64(newAllocId), 10) bufferInfo["up"] = strconv.FormatUint(valBuff-valFixedBuff, 10) // updateBuffer function takes updated buffer Information and store it in redis // returns error if unable to store allocation buffer in redis err = updateBuffer(bufferInfo) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } else { log.Info("Allocation uplink buffer is updated") } nextBwAllocIdAvailable++ } } else { log.Debug("Resources are insufficient for this allocation") } case "10": // getting downlink/uplink buffer value from redis to update _, valBuffup, err := getUplinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return } bufferInfo, valBuffdown, err := getDownlinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return } // To start allocating resource, buffer values should be non-zero if (valBuffup > 0) && (valBuffdown > 0) { var valFixedBuff uint64 valFixedBuff, err = strconv.ParseUint(bwInfo.FixedAllocation, 10, 64) // The value of resource needed to be allocate should also be no-zero if (valFixedBuff > 0) && (err == nil) { newAllocId := nextBwAllocIdAvailable bwInfo.AllocationId = strconv.FormatUint(uint64(newAllocId), 10) bufferInfo["up"] = strconv.FormatUint(valBuffup-(valFixedBuff/2), 10) bufferInfo["down"] = strconv.FormatUint(valBuffdown-(valFixedBuff/2), 10) // updateBuffer function takes updated buffer Information and store it in redis // returns error if unable to store allocation buffer in redis err = updateBuffer(bufferInfo) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } else { log.Info("Allocation downlink buffer is updated") } nextBwAllocIdAvailable++ } } else { log.Debug("Resources are insufficient for this allocation") } } // setBwInfo function takes input of new BW allocation information and Loading Loading @@ -2096,3 +1995,117 @@ func compareSessionFilters(key string, jsonInfo string, sessionFilterList interf } return nil } func bandwidthResourceAllocation(bwInfo BwInfo, w http.ResponseWriter) error { switch bwInfo.AllocationDirection { case "00": // getting downlink buffer value from redis to update bufferInfo, valBuff, err := getDownlinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return err } // To start allocating resource, buffer value should be non-zero if valBuff > 0 { var valFixedBuff uint64 valFixedBuff, err = strconv.ParseUint(bwInfo.FixedAllocation, 10, 64) // The value of resource needed to be allocate should also be no-zero if (valFixedBuff > 0) && (err == nil) { newAllocId := nextBwAllocIdAvailable bwInfo.AllocationId = strconv.FormatUint(uint64(newAllocId), 10) bufferInfo["down"] = strconv.FormatUint(valBuff-valFixedBuff, 10) // updateBuffer function takes updated buffer Information and store it in redis // returns error if unable to store allocation buffer in redis err = updateBuffer(bufferInfo) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return err } else { log.Info("Allocation downlink buffer is updated") } nextBwAllocIdAvailable++ // increment allocation ID } } else { log.Debug("Resources are insufficient for this allocation") } case "01": // getting uplink buffer value from redis to update bufferInfo, valBuff, err := getUplinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return err } // To start allocating resource, buffer value should be non-zero if valBuff > 0 { var valFixedBuff uint64 valFixedBuff, err = strconv.ParseUint(bwInfo.FixedAllocation, 10, 64) // The value of resource needed to be allocate should also be no-zero if (valFixedBuff > 0) && (err == nil) { newAllocId := nextBwAllocIdAvailable bwInfo.AllocationId = strconv.FormatUint(uint64(newAllocId), 10) bufferInfo["up"] = strconv.FormatUint(valBuff-valFixedBuff, 10) // updateBuffer function takes updated buffer Information and store it in redis // returns error if unable to store allocation buffer in redis err = updateBuffer(bufferInfo) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return err } else { log.Info("Allocation uplink buffer is updated") } nextBwAllocIdAvailable++ } } else { log.Debug("Resources are insufficient for this allocation") } case "10": // getting downlink/uplink buffer value from redis to update _, valBuffup, err := getUplinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return err } bufferInfo, valBuffdown, err := getDownlinkBuff() if err != nil { log.Error("Unable to fetch allocation buffer from redis") errHandlerProblemDetails(w, "Unable to fetch allocation buffer from redis", http.StatusInternalServerError) return err } // To start allocating resource, buffer values should be non-zero if (valBuffup > 0) && (valBuffdown > 0) { var valFixedBuff uint64 valFixedBuff, err = strconv.ParseUint(bwInfo.FixedAllocation, 10, 64) // The value of resource needed to be allocate should also be no-zero if (valFixedBuff > 0) && (err == nil) { newAllocId := nextBwAllocIdAvailable bwInfo.AllocationId = strconv.FormatUint(uint64(newAllocId), 10) bufferInfo["up"] = strconv.FormatUint(valBuffup-(valFixedBuff/2), 10) bufferInfo["down"] = strconv.FormatUint(valBuffdown-(valFixedBuff/2), 10) // updateBuffer function takes updated buffer Information and store it in redis // returns error if unable to store allocation buffer in redis err = updateBuffer(bufferInfo) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return err } else { log.Info("Allocation downlink buffer is updated") } nextBwAllocIdAvailable++ } } else { log.Debug("Resources are insufficient for this allocation") } } return nil }