blob: 7abd7f9d64391761d901f4de3d3935428bc38009 [file] [log] [blame]
Harald Welte6fff3642017-07-22 21:36:13 +02001module NS_Emulation {
2 import from NS_Types all;
3 import from BSSGP_Types all;
4 import from NS_CodecPort all;
5 import from NS_CodecPort_CtrlFunct all;
6 //import from IPL4asp_PortType all;
7 import from IPL4asp_Types all;
8
9 type record NsUnitdataRequest {
10 BssgpBvci bvci,
11 Nsei nsei,
12 octetstring sdu
13 }
14
15 type record NsUnitdataIndication {
16 BssgpBvci bvci,
17 Nsei nsei,
18 octetstring sdu
19 }
20
21 type enumerated NseState {
22 NSE_S_BLOCKED,
23 NSE_S_ALIVE,
24 NSE_S_RESET
25 };
26
27 /* port from our (internal) point of view */
28 type port NS_SP_PT message {
29 in NsUnitdataRequest;
30 out NsUnitdataIndication,
31 ASP_Event;
32 } with { extension "internal" };
33
34 /* port from the user point of view */
35 type port NS_PT message {
36 in ASP_Event,
37 NsUnitdataIndication;
38 out NsUnitdataRequest;
39 } with { extension "internal" };
40
41 function NSStart() runs on NS_CT {
42 f_init();
43 f_ScanEvents();
44 }
45
46 private function f_init() runs on NS_CT {
47 f_IPL4_connect(NSCP, remote_ip, remote_udp_port, local_ip, local_udp_port, 0, { udp := {}});
48 }
49
50 type component NS_CT {
51 /* UDP port towards the bottom (IUT) */
52 port NS_CODEC_PT NSCP;
53 /* NS-User SAP towards the user */
54 port NS_SP_PT NS_SP;
55
56 var NseState state;
57 var ConnectionId conn_id;
58 }
59
60 modulepar {
61 PortNumber local_udp_port := 23001;
62 charstring local_ip := "127.0.0.1";
63 PortNumber remote_udp_port := 23000;
64 charstring remote_ip := "127.0.0.1";
65 };
66
67 template NsTLV t_NS_IE_CAUSE(template NsCause cause) := {
68 iei := NS_IEI_CAUSE,
69 len := 1,
70 u := { cause := cause }
71 };
72
73 template NsTLV t_NS_IE_NSVCI(template Nsvci nsvci) := {
74 iei := NS_IEI_NSVCI,
75 len := 2,
76 u := { nsvci := nsvci }
77 }
78
79 template NsTLV t_NS_IE_NSEI(template Nsvci nsei) := {
80 iei := NS_IEI_NSEI,
81 len := 2,
82 u := { nsei := nsei }
83 }
84
85 template NsPdu t_NS_RESET(template NsCause cause, template Nsvci nsvci, template Nsei nsei) := {
86 pdu_type := NS_PDUT_NS_RESET,
87 u := {
88 other := {
89 tlvs := { t_NS_IE_CAUSE(cause), t_NS_IE_NSVCI(nsvci), t_NS_IE_NSEI(nsei) }
90 }
91 }
92 };
93
94 template NsPdu t_NS_RESET_ACK(template Nsvci nsvci, template Nsei nsei) := {
95 pdu_type := NS_PDUT_NS_RESET,
96 u := {
97 other := {
98 tlvs := { t_NS_IE_NSVCI(nsvci), t_NS_IE_NSEI(nsei) }
99 }
100 }
101 };
102
103 template NsPdu t_NS_SIMPLE(template NsPduType pdut) := { pdu_type := pdut, u := { other := { tlvs := {} } } };
104 template NsPdu t_NS_ALIVE := t_NS_SIMPLE(NS_PDUT_NS_ALIVE);
105 template NsPdu t_NS_ALIVE_ACK := t_NS_SIMPLE(NS_PDUT_NS_ALIVE_ACK);
106 template NsPdu t_NS_UNBLOCK := t_NS_SIMPLE(NS_PDUT_NS_UNBLOCK);
107 template NsPdu t_NS_UNBLOCK_ACK := t_NS_SIMPLE(NS_PDUT_NS_UNBLOCK_ACK);
108 template NsPdu t_NS_BLOCK := t_NS_SIMPLE(NS_PDUT_NS_BLOCK);
109 template NsPdu t_NS_BLOCK_ACK := t_NS_SIMPLE(NS_PDUT_NS_BLOCK_ACK);
110
111 template NS_Send t_NS_Send(template ConnectionId connId, template NsPdu msg) := {
112 connId := connId,
113 msg := msg
114 }
115
116 private function f_ScanEvents() runs on NS_CT {
117 var NsUnitdataRequest ud_req;
118 var NS_RecvFrom rf;
119 var ASP_Event evt;
120
121 while (true) {
122
123 if (state == NSE_S_BLOCKED) {
124 alt {
125 [] NSCP.receive(t_NS_RecvFrom(t_NS_BLOCK)) -> value rf {
126 NSCP.send(t_NS_Send(conn_id, t_NS_BLOCK_ACK));
127 }
128 [] NSCP.receive(t_NS_RecvFrom(t_NS_UNBLOCK)) -> value rf {
129 NSCP.send(t_NS_Send(conn_id, t_NS_UNBLOCK_ACK));
130 state := NSE_S_ALIVE;
131 }
132 [] NSCP.receive(ASP_Event:?) -> value evt { NS_SP.send(evt); }
133 }
134 } else if (state == NSE_S_ALIVE) {
135 alt {
136 [] NSCP.receive(t_NS_RecvFrom(t_NS_BLOCK)) -> value rf {
137 NSCP.send(t_NS_Send(conn_id, t_NS_BLOCK_ACK));
138 state := NSE_S_BLOCKED;
139 }
140 [] NSCP.receive(t_NS_RecvFrom(t_NS_UNBLOCK)) -> value rf {
141 NSCP.send(t_NS_Send(conn_id, t_NS_UNBLOCK_ACK));
142 }
143 [] NS_SP.receive(NsUnitdataRequest:?) -> value ud_req {
144 //NSCP.send(t_NS_Send(
145 }
146 [] NSCP.receive(ASP_Event:?) -> value evt { NS_SP.send(evt); }
147 }
148 } else if (state == NSE_S_RESET) {
149 alt {
150 [] NSCP.receive(ASP_Event:?) -> value evt { NS_SP.send(evt); }
151 }
152 }
153
154
155 }
156 }
157}