Commit 7d4a4e33 authored by Simon Pastor's avatar Simon Pastor Committed by Kevin Di Lallo
Browse files

flow rule fix to claim optimisations

parent 11561614
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -163,6 +163,7 @@ var podCountReq = 0
var podCount = 0
var svcCountReq = 0
var svcCount = 0
var nextTransactionId = 1

// Init - TC Engine initialization
func Init() (err error) {
@@ -254,8 +255,13 @@ func processActiveScenarioUpdate() {
		// Apply network characteristic rules
		applyNetCharRules()

		//Update the Db for state information (only transactionId for now)
		updateDbState(nextTransactionId)

		// Publish update to TC Sidecars for enforcement
		_ = Publish(channelTcNet, "")
		transactionIdStr := strconv.Itoa(nextTransactionId)
		_ = Publish(channelTcNet, transactionIdStr)
		nextTransactionId++
	}
}

@@ -799,6 +805,15 @@ func populateNetChar(nc *NetChar, latency int, latencyVariation int, latencyCorr
	nc.PacketLoss = packetLoss
}

func updateDbState(transactionId int) {

	var dbState = make(map[string]interface{})
	dbState["transactionIdStored"] = transactionId

	keyName := moduleTcEngine + ":" + typeNet + ":dbState"
	_ = DBSetEntry(keyName, dbState)
}

func applyNetCharRules() {
	log.Debug("applyNetCharRules")

+38 −4
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ import (
	"math/rand"
	"os"
	"os/exec"
	"strconv"
	"strings"
	"time"

@@ -83,6 +84,10 @@ var measurementsRunning = false
var flushRequired = false
var firstTimePass = true

var currentTransactionId = 0
var dbTransactionId = 0
var lastTransactionIdApplied = 0

// Run - MEEP Sidecar execution
func main() {
	// Initialize MEEP Sidecar
@@ -175,8 +180,11 @@ func eventHandler(channel string, payload string) {
}

func processNetCharMsg(payload string) {
	// NOTE: Payload contains no information yet. For now reevaluate Net Char rules on every received event.
	// NOTE: Payload contains only a transaction Id
	currentTransactionId, _ = strconv.Atoi(payload)
	_ = getTransactionIdApplied() //sets dbTransactionId and will apply it
	refreshNetCharRules()
	lastTransactionIdApplied = dbTransactionId
}

func processLbMsg(payload string) {
@@ -513,6 +521,21 @@ func createPingHandler(key string, fields map[string]string, userData interface{
	return nil
}

func getTransactionIdApplied() error {
	keyName := moduleTcEngine + ":" + typeNet + ":dbState"
	err := DBForEachEntry(keyName, getDbStateHandler, nil)
	if err != nil {
		return err
	}
	return nil
}

func getDbStateHandler(key string, fields map[string]string, userData interface{}) error {
	var err error
	dbTransactionId, err = strconv.Atoi(fields["transactionIdStored"])
	return err
}

func createIfbs() error {
	keyName := moduleTcEngine + ":" + typeNet + ":" + podName + ":shape*"
	err := DBForEachEntry(keyName, createIfbsHandler, nil)
@@ -525,9 +548,20 @@ func createIfbs() error {
func createIfbsHandler(key string, fields map[string]string, userData interface{}) error {
	ifbNumber := fields["ifb_uniqueId"]
	// Update the rule
	_, exists := filters[ifbNumber]

	if !exists {
		_ = cmdCreateIfb(fields)
		ifbs[ifbNumber] = ifbNumber
		_ = cmdSetIfb(fields)
	} else {
		if lastTransactionIdApplied < currentTransactionId {
			_ = cmdSetIfb(fields)
			log.Info("Transactions processed on the TC-Engine quicker than they can be processed: current ", currentTransactionId, " and last applied ", lastTransactionIdApplied)
		} else {
			log.Info("Transactions processed on the TC-Engine already applied ", currentTransactionId, " vs last applied ", lastTransactionIdApplied)
		}
	}

	return nil
}