blob: ea9ba3e3698e306f5e0bbd19da90e8be0d49a690 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2000-2018 Ericsson Telecom AB
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v2.0
// which accompanies this distribution, and is available at
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
///////////////////////////////////////////////////////////////////////////////
//
// File: STUN_Demo.ttcn
// Description: Demo for STUN Protocol module
// Rev: <RnXnn>
// Prodnr: CNL 113 644
// Updated: 2009-05-21
// Contact: http://ttcn.ericsson.se
// Reference: RFC 3489
///////////////////////////////////////////////
module STUN_Demo {
import from STUN_Types all;
import from STUN_Functions all;
modulepar charstring tsp_STUN_ip_address := "127.0.0.1"
type port STUN_PT message {
inout octetstring;
}
with
{ extension "internal"}
type component STUN_CT {
port STUN_PT STUN_PCO
var octetstring v_temp_msg;
var PDU_STUN v_msg_lasd_decoded, v_msg_to_send;
}
function f_STUN_sendMsg(PDU_STUN pl_msg, in octetstring pl_password := ''O) runs on STUN_CT {
v_temp_msg := f_STUN_Enc(pl_msg,pl_password);
log("f_STUN_sendMsg");
STUN_PCO.send(v_temp_msg);
}
function f_STUN_Demo_Orig_behavior() runs on STUN_CT
{
f_STUN_createMsgHeader(v_msg_to_send, Binding_Request);
f_STUN_appendResponseAddress(v_msg_to_send, {IP4, 1234,f_STUN_IP2oct("127.0.0.1")});
f_STUN_appendChangeRequest(v_msg_to_send, NO_CHANGE);
f_STUN_appendUsername(v_msg_to_send, "demo");
//f_STUN_appendMessageIntegrity(v_msg_to_send);
f_STUN_sendMsg(v_msg_to_send, '1234'O);
as_STUN_msgHandler();
log("v_msg_lasd_decoded", v_msg_lasd_decoded);
setverdict(pass);
self.stop;
}
function f_STUN_Demo_Term_behavior() runs on STUN_CT
{
as_STUN_msgHandler();
log("v_msg_lasd_decoded", v_msg_lasd_decoded);
f_STUN_createMsgHeader(v_msg_to_send, Binding_Response, v_msg_lasd_decoded.header.trans_id);
f_STUN_appendMappedAddress(v_msg_to_send, {IP4, 1234,f_STUN_IP2oct("127.0.0.1")});
f_STUN_appendSourceAddress(v_msg_to_send, {IP4, 1234,f_STUN_IP2oct("127.0.0.1")});
f_STUN_appendChangedAddress(v_msg_to_send, {IP4, 1234,f_STUN_IP2oct("127.0.0.1")});
f_STUN_appendMessageIntegrity(v_msg_to_send);
f_STUN_sendMsg(v_msg_to_send, '1234'O);
setverdict(pass);
self.stop;
}
altstep as_STUN_msgHandler() runs on STUN_CT {
[] STUN_PCO.receive(octetstring:?) -> value v_temp_msg
{
if (f_STUN_checkMessageIntegrity(v_temp_msg,'1234'O)) {
log("Good HMAC");
} else {
log("Bad HMAC");
}
v_msg_lasd_decoded := f_STUN_Dec(v_temp_msg);
}
}
testcase t_STUN_demo() runs on STUN_CT {
var STUN_CT c_STUN_orig;
var STUN_CT c_STUN_term;
c_STUN_orig := STUN_CT.create;
c_STUN_term := STUN_CT.create;
connect(c_STUN_orig:STUN_PCO,c_STUN_term:STUN_PCO);
c_STUN_term.start(f_STUN_Demo_Term_behavior());
c_STUN_orig.start(f_STUN_Demo_Orig_behavior());
all component.done
disconnect(c_STUN_orig:STUN_PCO,c_STUN_term:STUN_PCO);
mtc.kill;
}
control {
execute(t_STUN_demo());
}
}