VOL-3347 GEM ports kept for packet-outs should be in pon-onu-uni-vlan-pbit basis instead of per pon-onu-uni basis.
Change-Id: I7e9ca29295d28d97908a99ba8c34c4c9b52046c4
diff --git a/pkg/mocks/mockKVClient.go b/pkg/mocks/mockKVClient.go
index fe6310b..78cbef6 100644
--- a/pkg/mocks/mockKVClient.go
+++ b/pkg/mocks/mockKVClient.go
@@ -52,6 +52,8 @@
FlowGroup = "flow_groups"
//FlowGroupCached flow_groups_cached/<flow_group_id>
FlowGroupCached = "flow_groups_cached"
+ //OnuPacketIn to extract gem port from packet-in
+ OnuPacketIn = "onu_packetin"
)
// MockKVClient mocks the AdapterProxy interface.
@@ -178,6 +180,10 @@
return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
}
+ if strings.Contains(key, OnuPacketIn) {
+ return getPacketInGemPort(key)
+ }
+
maps := make(map[string]*kvstore.KVPair)
maps[key] = &kvstore.KVPair{Key: key}
return maps[key], nil
@@ -185,6 +191,44 @@
return nil, errors.New("key didn't find")
}
+//getPacketInGemPort returns the GEM port associated with the given key
+func getPacketInGemPort(key string) (*kvstore.KVPair, error) {
+ //parse interface, onu, uni, vlan, priority values
+ arr := getParamsFromPacketInKey(key)
+
+ if len(arr) < 5 {
+ return nil, errors.New("key didn't find")
+ }
+ if arr[0] == "1" && arr[1] == "1" && arr[2] == "3" && arr[3] == "0" && arr[4] == "0" {
+ str, _ := json.Marshal(3)
+ return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
+ }
+ if arr[0] == "2" && arr[1] == "2" && arr[2] == "4" && arr[3] == "549" && arr[4] == "0" {
+ str, _ := json.Marshal(4)
+ return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
+ }
+ if arr[0] == "1" && arr[1] == "2" && arr[2] == "2" && arr[3] == "48" && arr[4] == "7" {
+ str, _ := json.Marshal(2)
+ return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
+ }
+ return nil, errors.New("key didn't find")
+}
+
+//getParamsFromPacketInKey parse packetIn key that is in the format of "onu_packetin/{1,1,1,1,2}"
+func getParamsFromPacketInKey(key string) []string {
+ //return intfID, onuID, uniID, vlanID, priority
+ firstIndex := strings.Index(key, "{")
+ lastIndex := strings.Index(key, "}")
+ if firstIndex == -1 && lastIndex == -1 {
+ return []string{}
+ }
+ arr := strings.Split(key[firstIndex+1:lastIndex], ",")
+ if len(arr) < 5 {
+ return []string{}
+ }
+ return arr
+}
+
// Put mock function implementation for KVClient
func (kvclient *MockKVClient) Put(ctx context.Context, key string, value interface{}) error {
if key != "" {