Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling Expect Script from C++

Status
Not open for further replies.

daljman

Technical User
Apr 16, 2002
1
CA
I have written an Expect Script that I need to call from a testcase written in C++. I need the Expect script to be called prior to and after the testcase has done its magic.

Question: How do you call an Expect Script from C++.

Here's my C++ testcase:

====================================================
@TCID: ip99_expect
@GAP_PACKAGE:
set_reserve_timeout(60);
set_trace("LOGGING","ON");
GTP_TRACE="ON";

ip99_expect(resource_name1="gtp:sgsn_shasta_52",
resource_name3="msca:imsi_multi");

@GAP_TC:
#include <tc/TTF.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <gtp_codec/GTP_prot.h>
#include <gtp_ts/GTPTunnel.h>
#include <bss_ts/Mobile.h>

GTPTunnel sgsn(&quot;resource_name1&quot;, &quot;no_default&quot;);
Mobile ms(&quot;resource_name3&quot;, &quot;no_default&quot;);

//----------------------
// user_main
//----------------------
void ohm_main(void)
{
TTF_Result result;
SS7_Msg msg;
TTF_String imsi = &quot;5050241012160001&quot;;
TTF_String euAddress;
TTF_String steid;
TTF_String pdpAddress;
uint8 pdpType = 0;
uint8 nsapi = 4;


// Set up routing
sgsn.setPrimaryRouting(imsi, nsapi);

///////I want to call my script here

//----------------
// Bring Tunnel UP
//----------------

// Build &quot;Create PDP Context Request&quot; Message
msg.addIE(GTP_HDR_IE_VERSION_LFN, &quot;32&quot;);
msg.addIE(GTP_HDR_IE_MSG_TYPE, GTP_CPDPC_RQST);
//msg.addIE(GTP_HDR_IE_TEID, &quot;00000000&quot;);
msg.addIE(GTP_HDR_IE_SEQ_NUM, &quot;0001&quot;);
msg.addIE(GTP_HDR_IE_NPDN, &quot;00&quot;);
//msg.addIE(GTP_HDR_IE_EXT_HDR_TYPE, &quot;00&quot;);

msg.addIE(GTP_IE_IMSI, imsi);
msg.addIE(GTP_IE_SEL_MODE, &quot;fc&quot;);
//msg.addIE(GTP_IE_TEID_DATA, &quot;0000000a&quot;);
//msg.addIE(GTP_IE_TEID_SIG, &quot;0000000b&quot;);
msg.addIE(GTP_IE_NSAPI, nsapi);
msg.addIE(GTP_IE_EU_ADDR, &quot;f121&quot;); // IP Address: 0.0.0.0
msg.addIE(GTP_IE_APN, &quot;0474657374&quot;); // APN: &quot;test&quot;
//msg.addIE(GTP_IE_APN, &quot;046c327470&quot;); // APN: &quot;l2tp&quot;
//msg.addIE(GTP_IE_APN, &quot;056970736563&quot;); // APN: &quot;ipsec&quot;
//msg.addIE(GTP_IE_APN, &quot;0a726f72792d6970736563&quot;); // rory-ipsec
//msg.addIE(GTP_IE_APN, &quot;0661667368616e&quot;); // afshan (ipsec)
msg.addIE(GTP_IE_MSISDN, &quot;919137868588ff&quot;);
//msg.addIE(GTP_IE_QOS, &quot;012200007314010122060101&quot;);
//msg.addIE(GTP_IE_QOS, &quot;012200007314010122060101&quot;); // 68.5
//msg.addIE(GTP_IE_QOS, &quot;011203007314010122060101&quot;); // 68.6
//msg.addIE(GTP_IE_QOS, &quot;0122001f5314010122060101&quot;); // 68.7
//msg.addIE(GTP_IE_QOS, &quot;012200007314020222060909&quot;); // 68.8
//msg.addIE(GTP_IE_QOS, &quot;012200007314010197060101&quot;); // 68.9
//msg.addIE(GTP_IE_QOS, &quot;012190007314010122060101&quot;); // 68.10
msg.addIE(GTP_IE_QOS, &quot;012200007399010122f80101&quot;); // 68.11
//msg.addIE(GTP_IE_QOS, &quot;012200000114010122060101&quot;); // 68.12
//msg.addIE(GTP_IE_QOS, &quot;01e208e07314010122060101&quot;); // 68.13
//msg.addIE(GTP_IE_QOS, &quot;013a00007314010122060101&quot;); // 68.14
//msg.addIE(GTP_IE_QOS, &quot;016f00007314010122060101&quot;); // 68.15
//msg.addIE(GTP_IE_QOS, &quot;012200007314010122ff0101&quot;); // 68.16
//msg.addIE(GTP_IE_QOS, &quot;0122cc003314010122067fff&quot;); // 68.17
//msg.addIE(GTP_IE_QOS, &quot;032200007314010122060101&quot;); // 68.18
//msg.addIE(GTP_IE_QOS, &quot;032200003314010122060101&quot;); // 68.19
//msg.addIE(GTP_IE_QOS, &quot;022200009314010122060101&quot;); // 68.20
//msg.addIE(GTP_IE_QOS, &quot;01220000b314010122060101&quot;); // 68.21
//msg.addIE(GTP_IE_PRIVATE_EXT, &quot;0232020951001027006f25&quot;);


// Send the message to the GGSN
sgsn.send(msg);

// Expect to receive a message within 10000 milliseconds or 10 seconds
sgsn.receive(msg, 10000);

// Using the verifyIE methods of the SS7_Msg class to verify
// IEs in the received message.
msg.verifyIE(GTP_HDR_IE_MSG_TYPE, GTP_CPDPC_RESP);

// Get the IEs from the response message to be reused in the delete req
msg.getIE(GTP_IE_TEID_SIG, steid);


sgsn.getPDPAddress(msg, pdpType, pdpAddress);

sgsn.configureMobileIPRouting(result, pdpAddress);


// Intercepting Data Transfer
//sgsn.setOption(GTP_OPT_TX_LOGGING_ON);
//sgsn.setOption(GTP_OPT_TX_INTERCEPT_ON);
//sgsn.setOption(GTP_OPT_RX_LOGGING_ON);
//sgsn.setOption(GTP_OPT_RX_INTERCEPT_ON);



//************************//
//* RUN USER APPLICATION *//
//************************//

TTF_String application = &quot;/usr/X11R6/bin/xterm -display :$LOCAL_DISPLAY -geo 80x25 -bg '#770000' -fg white -T TUNNEL -n TUNNEL&quot;;

sgsn.launchApplicationInContext(result, application);

if (result.get_status() != TTF_OK)
{
report << &quot;*** ERROR Launching Application: &quot; << application << endl;
}
else
{
sgsn.waitUntilApplicationsFinish();
}



//------------------
// Bring Tunnel DOWN
//------------------

// Build &quot;Delete PDP Context Request&quot; Message

msg.clear();
msg.addIE(GTP_HDR_IE_VERSION_LFN, &quot;32&quot;);
msg.addIE(GTP_HDR_IE_MSG_TYPE, GTP_DPDPC_RQST);
msg.addIE(GTP_HDR_IE_TEID, steid);
msg.addIE(GTP_HDR_IE_SEQ_NUM, &quot;0002&quot;);
msg.addIE(GTP_HDR_IE_NPDN, &quot;00&quot;);


msg.addIE(GTP_IE_NSAPI, nsapi);

// Send the message to the SUT
sgsn.send(msg);


// Expect to receive a message within 10000 milliseconds or 10 seconds
sgsn.receive(msg, 10000);

// Using the verifyIE methods of the SS7_Msg class to verify
// IEs in the received message.
msg.verifyIE(GTP_HDR_IE_MSG_TYPE, GTP_DPDPC_RESP);


// Clear Routings
sgsn.clearRouting();


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top