Merge newe2 into master
[ric-plt/submgr.git] / pkg / teststub / rmrroutetable.go
1 /*
2 ==================================================================================
3   Copyright (c) 2019 AT&T Intellectual Property.
4   Copyright (c) 2019 Nokia
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 */
19
20 package teststub
21
22 import (
23         "strconv"
24 )
25
26 //-----------------------------------------------------------------------------
27 //
28 //-----------------------------------------------------------------------------
29
30 type RmrRouteTable struct {
31         routes []string
32         meids  []string
33 }
34
35 func (rrt *RmrRouteTable) AddRoute(mtype int, src string, subid int, trg string) {
36
37         line := "mse|"
38         line += strconv.FormatInt(int64(mtype), 10)
39         if len(src) > 0 {
40                 line += "," + src
41         }
42         line += "|"
43         line += strconv.FormatInt(int64(subid), 10)
44         line += "|"
45         line += trg
46         rrt.routes = append(rrt.routes, line)
47 }
48
49 func (rrt *RmrRouteTable) AddMeid(trg string, meids []string) {
50
51         line := "mme_ar"
52         line += "|"
53         line += trg
54         line += "|"
55         for _, str := range meids {
56                 line += " " + str
57         }
58         rrt.meids = append(rrt.meids, line)
59 }
60
61 func (rrt *RmrRouteTable) DelMeid(meids []string) {
62
63         line := "mme_del"
64         line += "|"
65         for _, str := range meids {
66                 line += " " + str
67         }
68         rrt.meids = append(rrt.meids, line)
69 }
70
71 func (rrt *RmrRouteTable) GetTable() string {
72         allrt := "newrt|start\n"
73         for _, val := range rrt.routes {
74                 allrt += val + "\n"
75         }
76         allrt += "newrt|end\n"
77         allrt += "meid_map | start\n"
78         for _, val := range rrt.meids {
79                 allrt += val + "\n"
80         }
81         allrt += "meid_map | end | " + strconv.FormatInt(int64(len(rrt.meids)), 10) + "\n"
82         return allrt
83 }