-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcc_rule.go
215 lines (193 loc) · 5.65 KB
/
pcc_rule.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package util
import (
"fmt"
"time"
"github.com/nycu-ucr/openapi/models"
)
var MediaTypeTo5qiMap = map[models.MediaType]int32{
models.MediaType_AUDIO: 1,
models.MediaType_VIDEO: 2,
models.MediaType_APPLICATION: 2,
models.MediaType_DATA: 9,
models.MediaType_CONTROL: 9,
models.MediaType_TEXT: 9,
models.MediaType_MESSAGE: 9,
models.MediaType_OTHER: 9,
}
// Create default pcc rule in PCF,
// TODO: use config file to pass default pcc rule
func CreateDefalutPccRules(id int32) *models.PccRule {
flowInfo := []models.FlowInformation{
{
FlowDescription: "permit out ip from any to assigned",
FlowDirection: models.FlowDirectionRm_DOWNLINK,
PacketFilterUsage: true,
PackFiltId: "PackFiltId-0",
},
{
FlowDescription: "permit out ip from any to assigned",
FlowDirection: models.FlowDirectionRm_DOWNLINK,
PacketFilterUsage: true,
PackFiltId: "PackFiltId-1",
},
}
return CreatePccRule(id, 10, flowInfo, "")
}
// Get pcc rule Identity(PccRuleId-%d)
func GetPccRuleId(id int32) string {
return fmt.Sprintf("PccRuleId-%d", id)
}
// Get qos Identity(QosId-%d)
func GetQosId(id int32) string {
return fmt.Sprintf("QosId-%d", id)
}
// Get Cond Identity(CondId-%d)
func GetCondId(id int32) string {
return fmt.Sprintf("CondId-%d", id)
}
// Get Traffic Control Identity(TcId-%d)
func GetTcId(id int32) string {
return fmt.Sprintf("TcId-%d", id)
}
// Get Charging Identity(ChgId-%d)
func GetChgId(id int32) string {
return fmt.Sprintf("ChgId-%d", id)
}
// Get Charging Identity(ChgId-%d)
func GetUmId(sponId, aspId string) string {
return fmt.Sprintf("umId-%s-%s", sponId, aspId)
}
// Get Packet Filter Identity(PackFiltId-%d)
func GetPackFiltId(id int32) string {
return fmt.Sprintf("PackFiltId-%d", id)
}
// Create Pcc Rule with param id, precedence, flow information, appID
func CreatePccRule(id, precedence int32, flowInfo []models.FlowInformation, appID string) *models.PccRule {
rule := models.PccRule{
AppId: appID,
FlowInfos: flowInfo,
PccRuleId: GetPccRuleId(id),
Precedence: precedence,
}
return &rule
}
func CreateCondData(id int32) models.ConditionData {
activationTime := time.Now()
return models.ConditionData{
CondId: GetCondId(id),
ActivationTime: &activationTime,
}
}
func CreateQosData(id, var5qi, arp int32) models.QosData {
return models.QosData{
QosId: GetQosId(id),
Var5qi: var5qi,
Arp: &models.Arp{
PriorityLevel: arp,
},
}
}
func CreateTcData(id int32, fullID string, flowStatus models.FlowStatus) *models.TrafficControlData {
if flowStatus == "" {
flowStatus = models.FlowStatus_ENABLED
}
if fullID == "" {
fullID = GetTcId(id)
}
return &models.TrafficControlData{
TcId: fullID,
FlowStatus: flowStatus,
}
}
func CreateUmData(umId string, thresh models.UsageThreshold) models.UsageMonitoringData {
return models.UsageMonitoringData{
UmId: umId,
VolumeThreshold: thresh.TotalVolume,
VolumeThresholdUplink: thresh.UplinkVolume,
VolumeThresholdDownlink: thresh.DownlinkVolume,
TimeThreshold: thresh.Duration,
}
}
// Convert Packet Filter information list to Flow Information List(Packet Filter Usage always true),
// EthDescription is Not Supported
func ConvertPacketInfoToFlowInformation(infos []models.PacketFilterInfo) (flowInfos []models.FlowInformation) {
for _, info := range infos {
flowInfo := models.FlowInformation{
FlowDescription: info.PackFiltCont,
PackFiltId: info.PackFiltId,
PacketFilterUsage: true,
TosTrafficClass: info.TosTrafficClass,
Spi: info.Spi,
FlowLabel: info.FlowLabel,
FlowDirection: models.FlowDirectionRm(info.FlowDirection),
}
flowInfos = append(flowInfos, flowInfo)
}
return
}
func GetPccRuleByAfAppId(pccRules map[string]*models.PccRule, afAppId string) *models.PccRule {
for _, pccRule := range pccRules {
if pccRule.AppId == afAppId {
return pccRule
}
}
return nil
}
func GetPccRuleByFlowInfos(pccRules map[string]*models.PccRule, flowInfos []models.FlowInformation) *models.PccRule {
found := false
set := make(map[string]models.FlowInformation)
for _, flowInfo := range flowInfos {
set[flowInfo.FlowDescription] = flowInfo
}
for _, pccRule := range pccRules {
found = true
for _, flowInfo := range pccRule.FlowInfos {
if _, exists := set[flowInfo.FlowDescription]; !exists {
found = false
break
}
}
if found {
return pccRule
}
}
return nil
}
func SetPccRuleRelatedData(decicion *models.SmPolicyDecision, pccRule *models.PccRule,
tcData *models.TrafficControlData, qosData *models.QosData, chgData *models.ChargingData,
umData *models.UsageMonitoringData) {
if tcData != nil {
if decicion.TraffContDecs == nil {
decicion.TraffContDecs = make(map[string]*models.TrafficControlData)
}
decicion.TraffContDecs[tcData.TcId] = tcData
pccRule.RefTcData = []string{tcData.TcId}
}
if qosData != nil {
if decicion.QosDecs == nil {
decicion.QosDecs = make(map[string]*models.QosData)
}
decicion.QosDecs[qosData.QosId] = qosData
pccRule.RefQosData = []string{qosData.QosId}
}
if chgData != nil {
if decicion.ChgDecs == nil {
decicion.ChgDecs = make(map[string]*models.ChargingData)
}
decicion.ChgDecs[chgData.ChgId] = chgData
pccRule.RefChgData = []string{chgData.ChgId}
}
if umData != nil {
if decicion.UmDecs == nil {
decicion.UmDecs = make(map[string]*models.UsageMonitoringData)
}
decicion.UmDecs[umData.UmId] = umData
pccRule.RefUmData = []string{umData.UmId}
}
if pccRule != nil {
if decicion.PccRules == nil {
decicion.PccRules = make(map[string]*models.PccRule)
}
decicion.PccRules[pccRule.PccRuleId] = pccRule
}
}