A.1 5G CNC Mediation Service RuleBook

Header Rule APIs

This section describes about the 5G CNC Mediation Service RuleBook.

Table -3 Header Rule APIs

S.no API Return type Description Rule Example
1 get(String key) String Returns a header value with that key. Request(headers.get("x-number") )
2 has(String key) Boolean Returns true/false depending on whether the header is present or not. Request(headers.has("3gpp-Sbi-Producer-Id"))
3 has(String key, String value) Boolean Returns true/false depending on whether the header is present with that value or not. Request(headers.has("3gpp-Sbi-Producer-Id","nfinst=1faf1bbc-6e4a-3994-a507-a14ef8e1bc23"))
4 put( String key, String value) Boolean Add the header with given key and value if does not find or updates the header with value if the given key found. req.headers.put("x-original-authority", "10.172.19.110:8080")
5 add( String key, String value); Boolean Add the header with given key and value if does not find req.headers.add("Content-type","application/json")
6 set( String key, String value); Boolean Updates the header with value if the given key found req.headers.set("3gpp-Sbi-Producer-Id","nfinst=1faf1bbc-6e4a-3994-a507-a14ef8e1bc25")
7 set( String key, String oldValue, String newValue); Boolean Update the header with new value if the existing value matches with oldValue req.headers.set("x-number", "2", "3")
8 del(String key) Boolean Delete the header req.headers.del("3gpp-Sbi-Message-Priority")
9 del(String key, String value) Boolean Delete the header if it matches with given key and value req.headers.del("x-forwarded-NF","NRF")
10 count(); Integer Returns the count of total numbers of all headers. Request(headers.count())
11 count(String key); Integer Returns the count of total numbers of headers with the key. Request(headers.count("Accept"))
12 count(String key, String value) Integer Returns the count of total numbers of headers with the key and value Request(headers.count("Accept","application/json"))
Example:
Rules configured:
 
    rule "New Rule1"
    when
       req : Request(headers.get("x-number")== 2)
    then
       req.headers.put("x-original-authority", "10.172.19.110:8080")
    end
    rule "New Rule2"
    when
       req : Request(headers.has("3gpp-Sbi-Producer-Id") && headers.has("3gpp-Sbi-Producer-Id","nfinst=1faf1bbc-6e4a-3994-a507-a14ef8e1bc23"))
    then
       req.headers.set("3gpp-Sbi-Producer-Id","nfinst=1faf1bbc-6e4a-3994-a507-a14ef8e1bc25")
       req.headers.set("x-number", "2", "3")
    end
    rule "New Rule3"
    when
       req : Request(headers.count() == 6)
    then
       req.headers.del("3gpp-Sbi-Message-Priority")
       req.headers.del("x-forwarded-NF","NRF")
    end
    rule "New Rule4"
    when
       req : Request(headers.count("Accept") == 2 && headers.count("Accept","application/json") == 1)
    then
       req.headers.add("Content-type","application/json")
    end
 
Request:
curl -v -H 'x-forwarded-NF: NRF' -H 'x-number: 2' -H 'Accept: application/json' -H "Accept: application/xml" -H "3gpp-Sbi-Producer-Id:nfinst=1faf1bbc-6e4a-3994-a507-a14ef8e1bc23" -H '3gpp-Sbi-Message-Priority: true' 'http://localhost:9090/nmediation-http/v1/'
 
Response:
HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: application/json
Content-Length: 339
 
{"mediationStatus":"SUCCESS","updatedHeaders":{"x-number":[["2","3"]],"3gpp-Sbi-Producer-Id":[["nfinst=1faf1bbc-6e4a-3994-a507-a14ef8e1bc23","nfinst=1faf1bbc-6e4a-3994-a507-a14ef8e1bc25"]]},"uri":"http://localhost:9090/nmediation-http/v1/","addedHeaders":{"x-original-authority":["10.172.19.110:8080"],"Content-type":["application/json"]}}  

Body Rule APIs

The following are the new body APIs which are being supported in mediation from release 22.2.0. The paths in all the parameters should always be in the JSONPath format.

Table -4 Body Rule APIs

S.no API Return type Description Example
1 get(String path) Object Returns the value present at that path. body.get("$.serviceName")
2 getAll(String path) List<Object> Returns the list of objects present at the path given. body.getAll("$.serviceName")
3 has(String path); boolean Checks if the key is present at that path or not. body.has("$.serviceName")
4 has(String path, Object value) boolean Checks if the key has the value present at that path or not. body.get("$.serviceName","value")
5 absPath(String arrayPath, String elem, Object value) Object Returns the whole path from head to the elem if the value is present. req.body.absPath("$.payload","iePath", "/a")
6 indexOf(String arrayPath, String elem, Object value) Integer Returns the index of the value in that JSONArray req.body.indexOf("$.dataToIntegrityProtectBlock.payload","value", 100)
7 put(String path, String key, T value) boolean Add the body with given key and value at path if does not find or updates the body with value at the path if the given key found. req.body.put("$","key","value")
8 add(String path, T value) boolean Adds the key embedded in the path with value given if element is not present. req.body.add("$.ipEndPoints","value")
9 set(String path, T value) boolean Updates the key embedded in the path with value given if element is present. rsp.body.add("$.ipEndPoints","value")
10 del(String path, T value) boolean Deletes the element at that path with the value present. Not supported. User can use the del (String path) api for delete. req.body.del("$.path","value")
11 del(String path) boolean Deletes the element at that path req.body.del("$.path")
Example:
Rules configured:      
    function Map<String,Object> ipEndPoints(String ipv4Address, String ipv6Address){
            Map< String,Object> ipEndPointObj = new HashMap< String,Object>();
            ipEndPointObj.put("ipv4Address", ipv4Address);
            ipEndPointObj.put("ipv6Address", ipv6Address);
            return ipEndPointObj;
    }
    rule "Rule_Request_body_1"
    when
       req : Request(body.has("$.ipEndPoints"))
    then
       req.body.put("$","dnn","d6n1")
       req.body.set("$.fqdn","amf.oracle.com")
       req.body.add("$.ipEndPoints",ipEndPoints("10.75.243.193","2001:0db8:85a3:0000:0000:8a2e:0370:7335"))
    end
    rule "Rule_Request_body_2"
    when
       req : Request(body.get("$.supi")=="imsi-1100000001" && body.has("$.suppFeat","All"))
    then
       req.body.del("$.supiOrSuci")
    end
   
Request:
curl -v -H 'x-forwarded-NF: NRF' -H 'Accept: application/json' -H "Content-type: application/json" -d '{"ipEndPoints":[{"ipv4Address":"10.75.243.203","ipv6Address":"2001:db8:85a3:8d3:1319:8a2e:370:7348"}],"servingNetworkName":"5G:mnc654.mcc987.3gppnetwork.org","supiOrSuci": "suci-0-987-654-0064-0-0-000000001", "fqdn": "pcf.oracle.com","notificationUri": "http://pcf1svc.trafficiot.odyssey.lab.us.oracle.com:80/notification/update", "pduSessionId": "2347", "sliceInfo": "adfg127", "supi": "imsi-1100000001", "suppFeat": "All" }' 'http://localhost:9090/nmediation-http/v1/'
 
Response:
HTTP/1.1 200 OK
Connection: keep-alive
{"mediationStatus":"SUCCESS","data":{"servingNetworkName":"5G:mnc654.mcc987.3gppnetwork.org","ipEndPoints":[{"ipv6Address":"2001:db8:85a3:8d3:1319:8a2e:370:7348","ipv4Address":"10.75.243.203"},{"ipv6Address":"2001:0db8:85a3:0000:0000:8a2e:0370:7335","ipv4Address":"10.75.243.193"}],"fqdn":"amf.oracle.com","notificationUri":"http://pcf1svc.trafficiot.odyssey.lab.us.oracle.com:80/notification/update","dnn":"d6n1","pduSessionId":"2347","sliceInfo":"adfg127","supi":"imsi-1100000001","suppFeat":"All"},"uri":"http://localhost:9090/nmediation-http/v1/"}

Http Message Common APIs

The following are the common APIs supported for request and response body.

Table -5 Http Message Common APIs

S.no API Return Type Description Example
1 getUri() String returns the URI of the Request req.getUri()
2 setUri(String URI) void Sets the URI in the body of request req.setUri("http://oracle.com")
3 getHttpStatusCode() Integer returns the StatusCode from the body of Response rsp.getHttpStatusCode()
4 setHttpStatusCode(Integer httpStatusCode) void sets the StatusCode in the body of Response rsp.setHttpStatusCode(201)
5 getRejectMessage() String returns the Reject Message from the body of Response rsp.getRejectMessage()
6 setRejectMessage(String rejectMessage) void sets the Reject Message in the body of Response rsp.setRejectMessage("Message")

Other Support for Rules

This section describes methods to create Mediation rules.

Regex Support:

The following example defines rules using regular expression on header API.

rule "regex rule"
when
   req : Request(headers.get("x-number")  matches "[0-9]")
then
   req.headers.put( "Header name", "value")
end
 
 
rule "regex rule2"
when
    req : Request(body.get("$.serviceName").toString() matches "suci-.*0-0-0.*")
then
    req.body.put("$","new key","value")
end
 
 
Example:
suci-0-123-45-0-0-0-0-1-17-e9b9916c911f448d8792e6b2f387f85d3ecab9040049427d9edbb5431b0bc711023be6a057f34956ba21b45d936238aebeb7

Operator on header API

The following example defines rules using in operator on header API.

rule "New Rule5"
when
   req : Request(headers.get("x-number")  in (1,2,3,4,5 ))
then
   req.headers.put( "Header name", "value")
end

Function Support

The following example defines rules using functions:
function String update(String str){
   int a = Integer.parseInt(str);
   a = a+1;
   str = ""+a;
   return str;
}
 
rule "Function"
when
   req : Request(headers.get("ADD")==1)
then
   req.headers.set("ADD",update(req.headers.get("ADD")))
end

Configuring Mediation Rules

Configuring Mediation Rules using ConfigMap
The following are the steps to configure the rules:
  1. Download the configMap into a file using the following command:
    kubectl get configmap ocsepp-nf-mediation-config-active -n seppsvc -oyaml >> rule_configmap.txt
  2. At the end of the file rule_configmap.txt , append the below data block along with needed rules:
    data:
      rule.drl: |
        package com.oracle.cgbu.ocmediation.nfmediation;
      
        import com.oracle.cgbu.ocmediation.nfruleengine.NFDroolsRuleEngine;
        import com.oracle.cgbu.ocmediation.factdetails.Request
        import com.oracle.cgbu.ocmediation.factdetails.Response;
        import java.util.Map;
        import java.util.HashMap;
      
        dialect "mvel"
          
        //rules
    Example of updated file:
    apiVersion: v1
    kind: ConfigMap
    metadata:
      creationTimestamp: "2022-08-10T14:01:27Z"
      name: ocsepp-nf-mediation-config-active
      namespace: seppsvc
      resourceVersion: "1635604"
      uid: b4ff6628-4e84-4aa7-8116-4daecbff8712
    data:
      rule.drl: |
        package com.oracle.cgbu.ocmediation.nfmediation;
      
        import com.oracle.cgbu.ocmediation.nfruleengine.NFDroolsRuleEngine;
        import com.oracle.cgbu.ocmediation.factdetails.Request
        import com.oracle.cgbu.ocmediation.factdetails.Response;
        import java.util.Map;
        import java.util.HashMap;
      
        dialect "mvel"
      
        rule "Rule_show_add_header"
        when
           req : Request(headers.has("3gpp-Sbi-Message-Priority") == true)
        then
           req.headers.add("3gpp-Sbi-Message-Priority","10")
           req.headers.del("x-test-req-header1")
        end
      
        rule "Rule_Request_body_add_delete"
        when
           req : Request(headers.has("x-forwarded-NF","NRF"))
        then
           req.body.put("$","nfId","ccc5ccbb-5bb9-465f-9ace-0faf08cb4223")
           req.body.del("$.supiOrSuci")
        end
  3. Run the following command to update the configmap with the updated rules:
    kubectl replace ocsepp-nf-mediation-config-active -n seppsvc -f rule_configmap.txt

    Note:

    • If rules changed on nf active mediation then use "$releaseName-nf-mediation-config-active" as the name of the configmap.
    • It is recommended to maintain the back up of the rules as it can lead to rule loss if the config map deleted

Rules for NF-Mediation:

function Map<Object, Object> addObject() {
    return new HashMap<Object, Object>();
}
 
function ArrayList<Object> addArray() {
    return new  ArrayList<Object>();
}
 
function Map<String,Object> ipEndPoints(String ipv4Address, String ipv6Address, String ipv6Prefix){
        Map< String,Object> ipEndPointObj = new HashMap< String,Object>();
        ipEndPointObj.put("ipv4Address", ipv4Address);
        ipEndPointObj.put("ipv6Address", ipv6Address);
        ipEndPointObj.put("ipv6Prefix",ipv6Prefix );
        return ipEndPointObj;
}
 
rule "New Rule1"
    agenda-group "scp"
when
    req : Request(body.get("$.apiPrefix")=="/mediation")
then
    req.headers.put("x-dest-path",req.body.get("$.apiPrefix").toString())
end
 
rule "New Rule2"
when
    req : Request(body.has("$.defaultNotificationSubscriptions[*].callbackUri","pcf.oracle.com/pcs/v1.0/nrf/notifycallback"))
then
    req.body.add("$.ipEndPoints",ipEndPoints("10.75.243.193","2001:0db8:85a3:0000:0000:8a2e:0370:7335","2001:0db8:85a3"))
 
end
 
rule "New Rule3"
when
    req : Request(headers.has("x-forwarded-NF","PCF") && body.has("$.fqdn","pcf.oracle.com"))
then
    req.headers.put("x-forwarded-NF","AMF")
    req.body.put("$","fqdn","amf.oracle.com")
end
 
rule "New Rule4"
when
    req : Request(body.get("$.serviceName")=="svc1")
then
    req.headers.del("x-service-name")
end
 
rule "New Rule5"
when
   req : Request(headers.get("x-number")  in (1,2,3,4,5 ))
then
   req.headers.put( "x-original-authority", "10.172.19.110:8080")
end
Configuring rules for PT

rule "pt_d2h_to_nf_rule"
salience 1
when
    req : Request(headers.has("pt_dest_uri"))
then
    req.setUri(req.headers.get("pt_dest_uri").replace("pcf.com","10.75.203.74:1000/simulation"))
    req.headers.del("pt_dest_uri")
end
 
rule "pt_rar_to_pcf_rule"
salience 1
when
  req : Request(req.getUri().toString() matches ".*(npcf-policyauthorization)*(v1)*(notification)*(notify).*")
then
 req.getHttpMessageFactImpl().forwardPath = IWFConsts.FORWARD_TO_H2D
 req.headers.add("diameterApplicationId","16777236")
 req.headers.add("diameterCommandCode","258")
 req.headers.add("original-req-uri",req.getUri())
end
 
rule "pt_aar_to_pcf_rule"
salience 1
when
  req : Request(req.body.has("$.ascReqData.notifUri"))
then
  req.body.add("$.ascReqData.notifUri",req.body.get("$.ascReqData.notifUri").toString().replace("iwf.com","10.75.203.74:30079"))
  req.body.add("$.ascReqData.evSubsc.notifUri",req.body.get("$.ascReqData.evSubsc.notifUri").toString().replace("iwf.com","10.75.203.74:30079"))
end
 
rule "pt_asr_to_pcf_rule"
salience 1
when
  req : Request(getUri().toString() matches ".*(npcf-policyauthorization)*(v1)*(notification)*(terminate).*")
then
  req.getHttpMessageFactImpl().forwardPath=IWFConsts.FORWARD_TO_H2D
  req.headers.add("diameterApplicationId","16777236")
  req.headers.add("diameterCommandCode","274")
  req.headers.add("original-req-uri",req.getUri())
end
 
 
rule "pt_ccri_to_h2d_rule"
salience 1
when
req : Request(req.getUri() matches ".*(npcf-smpolicycontrol/v1/sm-policies)(/$|$)")
then
req.getHttpMessageFactImpl().forwardPath=IWFConsts.FORWARD_TO_H2D
req.headers.put("diameterApplicationId","16777238")
req.headers.put("diameterCommandCode","272")
req.headers.put("requestType","CREATE")
end
 
rule "pt_ccru_to_h2d_rule"
salience 1
when
req : Request(req.getUri() == ".*(npcf-smpolicycontrol/v1/sm-policies/)(.*)(/update)(/$|$)")
then
req.getHttpMessageFactImpl().forwardPath=IWFConsts.FORWARD_TO_H2D
req.headers.put("diameterApplicationId","16777238")
req.headers.put("diameterCommandCode","272")
req.headers.put("requestType","UPDATE")
req.headers.put("original-req-uri",req.getUri())
end
 
rule "pt_ccrt_to_h2d_rule"
salience 1
when
req : Request(req.getUri() matches ".*(npcf-smpolicycontrol/v1/sm-policies/)(.*)(/delete)(/$|$)")
then
req.getHttpMessageFactImpl().forwardPath=IWFConsts.FORWARD_TO_H2D
req.headers.put("diameterApplicationId","16777238")
req.headers.put("diameterCommandCode","272")
req.headers.put("requestType","DELETE")
req.headers.put("original-req-uri",req.getUri())
end