1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
12 ******************************************************************************/
16 /*** *** *** *** PDU *** *** *** ***/
25 with { variant (s) "FIELDLENGTH(8)" }
27 /*** *** *** *** Ports *** *** *** ***/
28 type port UNDER message {
31 with { extension "provider" }
33 type port SENDER message {
36 with { extension "user UNDER
37 out(PDU1 -> octetstring : function(p1o))
38 in (octetstring -> - : discard)
41 type port RECEIVER message {
44 with { extension "user UNDER
45 //out(PDU1 -> - : discard)
46 in (octetstring -> PDU2 : function(op2sl))
49 /*** *** *** *** mapper functions *** *** *** ***/
51 // A "prototype(fast)" implemented in TTCN
52 function p1o(in PDU1 p, out octetstring o) {
55 with { extension "prototype(fast)" }
57 function op2(in octetstring o, out PDU2 p) {
60 with { extension "prototype(fast)" }
62 // A "prototype(sliding)" implemented in TTCN
63 function op2sl(inout octetstring o, out PDU2 p) return integer {
64 //log(">>> op2sl ", o);
65 var integer lo := lengthof(o); // octets, 'ABCD' = 2
67 //log("<<< return 2: not enough:", lo)
70 //else { log("=== length is ", lo) }
71 p.s := oct2char(substr(o, 0, 8)); // "decode" the PDU
72 o := substr(o, 8, lo-8); // return the rest
73 //log(">>> res=", p.s);
75 //log(">>> return 0");
78 with { extension "prototype(sliding)" }
80 /*** *** *** *** Components *** *** *** ***/
82 port SENDER stringport;
83 port RECEIVER reverseport;
84 port SENDER another_stringport;
88 //port PT1 SYSTEM_PORT2;
91 /*** *** *** *** Testcases *** *** *** ***/
93 // Intrernal communication with mapped ports
94 testcase intern() runs on D2
96 connect (mtc:stringport, mtc:reverseport);
97 var PDU1 cr := { "howdy!" }
100 [] reverseport.receive /* anything */ { setverdict(fail, "premature receive"); }
101 [else] { setverdict(pass); } // less than eight bytes: shouldn't receive anything
104 stringport.send(PDU1 : { "??" }) // the missing two bytes
106 [] reverseport.receive(PDU2 : {"howdy!??"}) { setverdict(pass); }
107 [] reverseport.receive { setverdict(fail, "wrong receive"); }
108 [else] { setverdict(fail, "no receive"); }
110 disconnect(mtc:stringport, mtc:reverseport);
115 octetstring s, // EXTENSION_BIT not implemented for charstring
118 with { variant ""; /*FIELDLENGTH(8)*/
119 variant (s) "EXTENSION_BIT(yes)";
120 variant (i) "FIELDLENGTH(24)"; // bits
123 external function enc3(in PDU3 p) return octetstring
124 with { extension "prototype(convert) encode(RAW)" }
126 external function dec3(in octetstring o) return PDU3
127 with { extension "prototype(convert) decode(RAW)" }
129 external function dec3sl(inout octetstring o, out PDU3 p) return integer
130 with { extension "prototype(sliding) decode(RAW) errorbehavior(INVAL_MSG:WARNING,INCOMPL_MSG:WARNING)" }
132 // Try to elicit various return values from the decoder function
133 testcase errored() runs on D2 system D2
135 connect(mtc:stringport, mtc:reverseport);
136 var PDU1 p1 := { "yay....." }
140 [] reverseport.receive(PDU2 : ?) { setverdict(pass, "got PDU2"); }
141 [else] { setverdict(fail, "no receive at ", __LINE__); }
144 var octetstring three := char2oct("three!!!");
145 var PDU3 p0 := { s := three, i := 3 };
146 var octetstring o := enc3(p0);
147 var octetstring incompl;
151 log("=== === === === encoded as ", o);
152 incompl := '74687265652121A11B0000'O; // "three!!!"
153 //p := dec3(incompl);
154 retval := dec3sl(incompl, p);
156 if (retval == 0) { setverdict(pass) }
157 else { setverdict(fail, "nonzero at ", __LINE__); }
162 log("___ string only ___");
163 incompl := '74687265652121A1'O;
164 retval := dec3sl(incompl, p);
166 if (retval == 2) { setverdict(pass) }
167 else { setverdict(fail, "not 2 at ", __LINE__); }
172 log("___ plus nine ___");
173 incompl := hex2oct('74687265652121A130'H);
174 retval := dec3sl(incompl, p);
176 if (retval == 1) { setverdict(pass) }
177 else { setverdict(fail, "not 1 at ", __LINE__); }
179 disconnect(mtc:stringport, mtc:reverseport);
182 // Test sliding decoding with multiple connections
183 testcase two_conn() runs on D2
185 connect(mtc:stringport, mtc:reverseport);
186 connect(mtc:another_stringport, mtc:reverseport);
188 var PDU1 p1a := { "ABCD" }, p1e := { "EFGH" }
190 stringport.send(p1a); // first half
192 [] reverseport.receive /* anything */{
193 setverdict(fail, "It wasn't supposed to receive anything yet");
195 [else] /* nothing received */ { setverdict(pass); }
198 another_stringport.send(p1a); // send first half on another connection
200 [] reverseport.receive /* anything */{
201 // If the different connections were not properly separated,
202 // a message would appear at this point (eight characters => one message)
203 setverdict(fail, "It STILL wasn't supposed to receive anything yet");
205 [else] /* nothing received */ { setverdict(pass); }
208 stringport.send(p1e); // send second half on the first connection
210 [] reverseport.receive( PDU2 : {"ABCDEFGH"} ) { setverdict(pass); }
211 [else] { setverdict(fail, "no receive"); }
214 another_stringport.send(p1e); // send second half on the second connection
216 [] reverseport.receive( PDU2 : {"ABCDEFGH"} ) { setverdict(pass); }
217 [else] { setverdict(fail, "no receive"); }
220 disconnect(mtc:stringport, mtc:reverseport);
221 disconnect(mtc:another_stringport, mtc:reverseport);