TrafficManagementAPI_Functions.ttcn 10.4 KB
Newer Older
module TrafficManagementAPI_Functions {
  
  // JSON
  import from JSON all;
  
  // LibCommon
  import from LibCommon_BasicTypesAndValues all;
  import from LibCommon_Time all;
  import from LibCommon_VerdictControl all;
  import from LibCommon_Sync all;

  // LibHttp
  import from LibItsHttp_TypesAndValues all;
  import from LibItsHttp_Functions all;
  import from LibItsHttp_Templates all;
  import from LibItsHttp_JsonTemplates all;
  import from LibItsHttp_TestSystem all;

  // LibMec/TrafficManagementAPI
  import from TrafficManagementAPI_TypesAndValues all;
  import from TrafficManagementAPI_Templates all;
  import from TrafficManagementAPI_Pixits all;

  // LibMec
  import from LibMec_Templates all;
  import from LibMec_Functions all;
  import from LibMec_Pics all;
  import from LibMec_Pixits all;

  function f_create_bw_allocation_resource(
                                           in JSON.String p_app_instance_id,
                                           out charstring p_bw_allocation_id,
                                           out BwInfo p_bw_info
                                           ) runs on HttpComponent {
    var Headers v_headers;
    var HttpMessage v_response;

    p_bw_allocation_id := "";
    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
                  m_http_request(
                                 m_http_request_post(
                                                     PX_ME_BWM_URI,
                                                     v_headers,
                                                     m_http_message_body_json(
                                                                              m_body_json_bw_info(
                                                                                                  m_bw_info(
                                                                                                            p_app_instance_id,
                                                                                                            APPLICATION_SPECIFIC_BW_ALLOCATION, // Request type
                                                                                                            "1024", // FixedAllocation
                                                                                                            Downlink // AllocationDirection
                                                                                                            ))))));
    tc_ac.start;
    alt {
      [] httpPort.receive(
                          mw_http_response(
YannGarcia's avatar
YannGarcia committed
                                           mw_http_response_201_created(
                                                                        mw_http_message_body_json(
                                                                                                  mw_body_json_bw_info(
                                                                                                                       mw_bw_info(
                                                                                                                                  p_app_instance_id
                                                                                                                                  )))))) -> value v_response {
        var charstring_list v_bw_allocation_id;
        
        tc_ac.stop;

YannGarcia's avatar
YannGarcia committed
        log("f_create_bw_allocation_resource: BwInfo resource created: ", v_response);
        f_get_header(valueof(v_response.response.header), "Location", v_bw_allocation_id);
        if (lengthof(v_bw_allocation_id) != 0) {
          p_bw_allocation_id := v_bw_allocation_id[0];
          p_bw_info := v_response.response.body.json_body.bwInfo;
        }
      }
      [] tc_ac.timeout {
        log("f_create_bw_allocation_resource: Expected message not received");
      }
    } // End of 'alt' statement
  } // End of function f_create_bw_allocation_resource

  function f_delete_bw_allocation_resource(
                                           in JSON.String p_app_instance_id,
                                           in charstring p_bw_allocation_id
                                           ) runs on HttpComponent {
    var Headers v_headers;

    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
                  m_http_request(
                                 m_http_request_delete(
                                                       PX_ME_BWM_URI & "/" & p_bw_allocation_id,
                                                       v_headers
                                                       )));
    tc_ac.start;
    alt {
      [] httpPort.receive(
                          mw_http_response(
                                           mw_http_response_204_no_content
                                           )) {
YannGarcia's avatar
YannGarcia committed
        tc_ac.stop;
      }
      [] tc_ac.timeout {
        log("f_delete_bw_allocation_resource: Expected message not received");
      }
    } // End of 'alt' statement
  } // End of function f_delete_bw_allocation_resource

  function f_create_mts_session_info_resource(
                                              in JSON.String p_app_instance_id,
                                              out charstring p_mts_session_id,
                                              out MtsSessionInfo p_mts_session_info
                                              ) runs on HttpComponent {
    var Headers v_headers;
    var HttpMessage v_response;

    p_mts_session_id := "";
    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
                  m_http_request(
                                 m_http_request_post(
                                                     PX_ME_MTS_SESSIONS_URI,
                                                     v_headers,
                                                     m_http_message_body_json(
                                                                              m_body_json_mts_session_info(
                                                                                                           m_mts_session_info(
                                                                                                                              PX_APP_INSTANCE_ID,
                                                                                                                              APPLICATION_SPECIFIC_MTS_ALLOCATION, // Request type
                                                                                                                              m_qosd, // QoS
                                                                                                                              LowCost, // MtsMode
                                                                                                                              Downlink, // TrafficDirection
                                                                                                                              {
                                                                                                                                m_session_filter(
                                                                                                                                                 "10.10.10.10",
                                                                                                                                                 {"1010"}
                                                                                                                                                 )
                                                                                                                                } // FlowFilter
                                                                                                                              ))))));
    tc_ac.start;
    alt {
      [] httpPort.receive(
                          mw_http_response(
YannGarcia's avatar
YannGarcia committed
                                           mw_http_response_201_created(
                                                                        mw_http_message_body_json(
                                                                                                  mw_body_json_mts_session_info(
                                                                                                                                mw_mts_session_info(
                                                                                                                                                    p_app_instance_id
                                                                                                                                                    )))))) -> value v_response {
        var charstring_list v_mts_session_info_id;
        
        tc_ac.stop;

YannGarcia's avatar
YannGarcia committed
        log("f_create_mts_session_info_resource: BwInfo resource created: ", v_response);
        f_get_header(valueof(v_response.response.header), "Location", v_mts_session_info_id);
        if (lengthof(v_mts_session_info_id) != 0) {
          p_mts_session_id := v_mts_session_info_id[0];
          p_mts_session_info := v_response.response.body.json_body.mtsSessionInfo;
        }
      }
      [] tc_ac.timeout {
        log("f_create_mts_session_info_resource: Expected message not received");
      }
    } // End of 'alt' statement
  } // End of function f_create_mts_session_info_resource

  function f_delete_mts_session_info_resource(
                                           in JSON.String p_app_instance_id,
                                           in charstring p_mts_session_id
                                           ) runs on HttpComponent {
    var Headers v_headers;

    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
                  m_http_request(
                                 m_http_request_delete(
                                                       PX_ME_MTS_SESSIONS_URI & "/" & p_mts_session_id,
                                                       v_headers
                                                       )));
    tc_ac.start;
    alt {
      [] httpPort.receive(
                          mw_http_response(
                                           mw_http_response_204_no_content
                                           )) {
YannGarcia's avatar
YannGarcia committed
        tc_ac.stop;
      }
      [] tc_ac.timeout {
        log("f_delete_mts_session_info_resource: Expected message not received");
      }
    } // End of 'alt' statement
  } // End of function f_delete_mts_session_info_resource

} // End of module TrafficManagementAPI_Functions