LibItsGeoNetworking_Encdec.cc 12.3 KB
Newer Older
1
#include "LibItsGeoNetworking_EncdecDeclarations.hh"
2

garciay's avatar
garciay committed
3
4
5
#include "GeoNetworkingCodec.hh"
#include "loggers.hh"

6
namespace LibItsGeoNetworking__EncdecDeclarations {
garciay's avatar
garciay committed
7
8
9
10
11
12
13
14
15
16
  
  /****************************************************
   * @desc    External function to encode a GeoNetworkingReq type
   * @param   value to encode
   * @return  encoded value
   ****************************************************/
  BITSTRING fx__enc__GeoNetworkingReq(LibItsGeoNetworking__TestSystem::GeoNetworkingReq const& p_geoNetworkingReq)
  {
    loggers::get_instance().log_msg(">>> fx__enc__GeoNetworkingReq: ", p_geoNetworkingReq);
    
garciay's avatar
garciay committed
17
18
19
    float duration;
    std::string tag("fx__enc__GeoNetworkingReq");
    loggers::get_instance().set_start_time(tag);
garciay's avatar
garciay committed
20
    GeoNetworkingCodec codec;
garciay's avatar
garciay committed
21
    OCTETSTRING os;
garciay's avatar
garciay committed
22
23
24
25
26
27
28
29
30
31
32
33
34
    if (codec.encode(p_geoNetworkingReq.msgOut(), os) == -1) {
      loggers::get_instance().warning("fx__enc__GeoNetworkingReq: -1 result code was returned");
      return int2bit(0, 1);
    }
    TTCN_Buffer encoding_buffer(os);
    for (int i = 1; i < p_geoNetworkingReq.get_count(); i++) {
      loggers::get_instance().log("fx__enc__GeoNetworkingReq: processing %s/%s/%s - %d - %d", p_geoNetworkingReq.fld_name(i), p_geoNetworkingReq.fld_descr(i)->name, p_geoNetworkingReq.get_at(i)->get_descriptor()->name, p_geoNetworkingReq.get_at(i)->is_optional(), p_geoNetworkingReq.get_at(i)->is_present());
      if (p_geoNetworkingReq.get_at(i)->is_optional() && p_geoNetworkingReq.get_at(i)->is_present()) {
	p_geoNetworkingReq.get_at(i)->get_opt_value()->encode(*p_geoNetworkingReq.fld_descr(i), encoding_buffer, TTCN_EncDec::CT_RAW);
      } else {
	p_geoNetworkingReq.get_at(i)->encode(*p_geoNetworkingReq.fld_descr(i), encoding_buffer, TTCN_EncDec::CT_RAW);
      }
    } // End of 'for' statement
garciay's avatar
garciay committed
35
    loggers::get_instance().set_stop_time(tag, duration);
garciay's avatar
garciay committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    
    return oct2bit(OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()));
  }

  /****************************************************
   * @desc    External function to decode a GeoNetworkingReq type
   * @param   value to encode
   * @return  encoded value
   ****************************************************/

  INTEGER fx__dec__GeoNetworkingReq(BITSTRING& b, LibItsGeoNetworking__TestSystem::GeoNetworkingReq& p)
  {
    loggers::get_instance().log(">>> fx__dec__GeoNetworkingReq");
    GeoNetworkingCodec codec;
    LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu pdu;
    OCTETSTRING is = bit2oct(b);

    // Calculate the size of the lower layers information
garciay's avatar
garciay committed
54
55
56
57
    int s = (
	     LibItsGeoNetworking__TestSystem::GeoNetworkingInd_macDestinationAddress_raw_.fieldlength +
	     LibItsGeoNetworking__TestSystem::GeoNetworkingInd_its__aid_raw_.fieldlength
	     ) / 8;
garciay's avatar
garciay committed
58
59
60
61
62
    if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast<const unsigned char *>(is)), pdu) == -1) {
      loggers::get_instance().warning("fx__dec__GeoNetworkingReq: -1 result code was returned");
      return -1;
    }
    p.msgOut() = pdu;
garciay's avatar
garciay committed
63
64
    TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast<const unsigned char *>(is) + is.lengthof() - s));
    loggers::get_instance().log_to_hexa("fx__dec__GeoNetworkingInd: Lower layer: ", decoding_buffer);
garciay's avatar
garciay committed
65
    for (int i = 1; i < p.get_count(); i++) {
garciay's avatar
garciay committed
66
      loggers::get_instance().log("fx__dec__GeoNetworkingReq: processing %s/%s/%s", p.fld_name(i), p.fld_descr(i)->name, p.get_at(i)->get_descriptor()->name);
garciay's avatar
garciay committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
      p.get_at(i)->decode(*p.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW);      
    } // End of 'for' statement
    
    return 0;
  }

  /****************************************************
   * @desc    External function to encode a GeoNetworkingInd type
   * @param   value to encode
   * @return  encoded value
   ****************************************************/
  BITSTRING fx__enc__GeoNetworkingInd(LibItsGeoNetworking__TestSystem::GeoNetworkingInd const& p_geoNetworkingInd)
  {
    loggers::get_instance().log_msg(">>> fx__enc__GeoNetworkingInd: ", p_geoNetworkingInd);
    
    GeoNetworkingCodec codec;
    OCTETSTRING os;
    if (codec.encode(p_geoNetworkingInd.msgIn(), os) == -1) {
      loggers::get_instance().warning("fx__enc__GeoNetworkingInd: -1 result code was returned");
      return int2bit(0, 1);
    }
    TTCN_Buffer encoding_buffer(os);
    for (int i = 1; i < p_geoNetworkingInd.get_count(); i++) {
      loggers::get_instance().log("fx__enc__GeoNetworkingInd: processing %s/%s/%s - %d - %d", p_geoNetworkingInd.fld_name(i), p_geoNetworkingInd.fld_descr(i)->name, p_geoNetworkingInd.get_at(i)->get_descriptor()->name, p_geoNetworkingInd.get_at(i)->is_optional(), p_geoNetworkingInd.get_at(i)->is_present());
      if (p_geoNetworkingInd.get_at(i)->is_optional() && p_geoNetworkingInd.get_at(i)->is_present()) {
	p_geoNetworkingInd.get_at(i)->get_opt_value()->encode(*p_geoNetworkingInd.fld_descr(i), encoding_buffer, TTCN_EncDec::CT_RAW);
      } else {
	p_geoNetworkingInd.get_at(i)->encode(*p_geoNetworkingInd.fld_descr(i), encoding_buffer, TTCN_EncDec::CT_RAW);
      }
    } // End of 'for' statement
    
    return oct2bit(OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()));
  }

  /****************************************************
   * @desc    External function to decode a GeoNetworkingInd type
   * @param   value to encode
   * @return  encoded value
   ****************************************************/

  INTEGER fx__dec__GeoNetworkingInd(BITSTRING& b, LibItsGeoNetworking__TestSystem::GeoNetworkingInd& p_geoNetworkingInd)
  {
    loggers::get_instance().log(">>> fx__dec__GeoNetworkingInd");
    
garciay's avatar
garciay committed
111
112
113
114
    float duration;
    std::string tag("fx__dec__GeoNetworkingInd");
    loggers::get_instance().set_start_time(tag);
    
garciay's avatar
garciay committed
115
116
117
118
119
    GeoNetworkingCodec codec;
    LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu pdu;
    OCTETSTRING is = bit2oct(b);

    // Calculate the size of the lower layers information
garciay's avatar
garciay committed
120
121
122
123
124
    int s = (
	     LibItsGeoNetworking__TestSystem::GeoNetworkingInd_macDestinationAddress_raw_.fieldlength +
	     LibItsGeoNetworking__TestSystem::GeoNetworkingInd_ssp_raw_.fieldlength +
	     LibItsGeoNetworking__TestSystem::GeoNetworkingInd_its__aid_raw_.fieldlength
	     ) / 8;
garciay's avatar
garciay committed
125
126
127
128
129
    if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast<const unsigned char *>(is)), pdu) == -1) {
      loggers::get_instance().warning("fx__dec__GeoNetworkingInd: -1 result code was returned");
      return -1;
    }
    p_geoNetworkingInd.msgIn() = pdu;
garciay's avatar
garciay committed
130
131
    TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast<const unsigned char *>(is) + is.lengthof() - s));
    loggers::get_instance().log_to_hexa("fx__dec__GeoNetworkingInd: Lower layer: ", decoding_buffer);
garciay's avatar
garciay committed
132
133
134
    for (int i = 1; i < p_geoNetworkingInd.get_count(); i++) {
      loggers::get_instance().log("fx__dec__GeoNetworkingInd: processing %s/%s/%s - %d - %d", p_geoNetworkingInd.fld_name(i), p_geoNetworkingInd.fld_descr(i)->name, p_geoNetworkingInd.get_at(i)->get_descriptor()->name, p_geoNetworkingInd.get_at(i)->is_optional(), p_geoNetworkingInd.get_at(i)->is_present());
      if (p_geoNetworkingInd.get_at(i)->is_optional()) {
garciay's avatar
garciay committed
135
	loggers::get_instance().log("fx__dec__GeoNetworkingInd: Bytes remaining: %d - field lenth: %d", decoding_buffer.get_len() - decoding_buffer.get_pos(), p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8);
garciay's avatar
garciay committed
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
	if (std::string(p_geoNetworkingInd.fld_name(i)).compare("ssp") == 0) {
	  if ((decoding_buffer.get_len() - decoding_buffer.get_pos()) >= p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8) {
	    loggers::get_instance().log("fx__dec__GeoNetworkingInd: decoding %s", p_geoNetworkingInd.fld_descr(i)->name);
	    BITSTRING ssp;
	    ssp.decode(*p_geoNetworkingInd.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW);
	    loggers::get_instance().log_msg("fx__dec__GeoNetworkingInd: ssp=", ssp);
	    dynamic_cast<OPTIONAL<BITSTRING> &>(*p_geoNetworkingInd.get_at(i)) = OPTIONAL<BITSTRING>(ssp);
	  } else {
	    loggers::get_instance().log("fx__dec__GeoNetworkingInd: set %s to omit", p_geoNetworkingInd.fld_descr(i)->name);
	    dynamic_cast<OPTIONAL<BITSTRING> &>(*p_geoNetworkingInd.get_at(i)).set_to_omit();
	  }
	} else if (std::string(p_geoNetworkingInd.fld_name(i)).compare("its_aid") == 0) {
	loggers::get_instance().log("fx__dec__GeoNetworkingInd: Bytes remaining: %d - its_aid lenth: %d", decoding_buffer.get_len() - decoding_buffer.get_pos(), p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8);
	  if ((decoding_buffer.get_len() - decoding_buffer.get_pos()) >= p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8) {
	    INTEGER its_aid;
	    its_aid.decode(*p_geoNetworkingInd.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW);
	    loggers::get_instance().log_msg("fx__dec__GeoNetworkingInd: its_aid=", its_aid);
	    dynamic_cast<OPTIONAL<INTEGER> &>(*p_geoNetworkingInd.get_at(i)) = OPTIONAL<INTEGER>(its_aid); 
	  } else {
	    loggers::get_instance().log("fx__dec__GeoNetworkingInd: set %s to omit", p_geoNetworkingInd.fld_descr(i)->name);
	    dynamic_cast<OPTIONAL<INTEGER> &>(*p_geoNetworkingInd.get_at(i)).set_to_omit();
	  }
	} else {
	  loggers::get_instance().log("fx__dec__GeoNetworkingInd(1): decoding %s", p_geoNetworkingInd.fld_descr(i)->name);
	  p_geoNetworkingInd.get_at(i)->decode(*p_geoNetworkingInd.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW);
	}
      } else {
	loggers::get_instance().log("fx__dec__GeoNetworkingInd(2): decoding %s", p_geoNetworkingInd.fld_descr(i)->name);
	  p_geoNetworkingInd.get_at(i)->decode(*p_geoNetworkingInd.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW);
      }
    } // End of 'for' statement
garciay's avatar
garciay committed
167
    loggers::get_instance().set_stop_time(tag, duration);
garciay's avatar
garciay committed
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

    loggers::get_instance().log_msg("<<< fx__dec__GeoNetworkingInd: ", p_geoNetworkingInd);
    return 0;
  }

  /****************************************************
   * @desc    External function to encode a GeoNetworkingPdu type
   * @param   value to encode
   * @return  encoded value
   ****************************************************/
  BITSTRING fx__enc__GeoNetworkingPdu(LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu const& p_geoNetworkingPdu)
  {
    loggers::get_instance().log_msg(">>> fx__enc__GeoNetworkingPdu: ", p_geoNetworkingPdu);
    
    GeoNetworkingCodec codec;
    OCTETSTRING os;
    codec.encode(p_geoNetworkingPdu, os);
garciay's avatar
garciay committed
185
    return oct2bit(os);
garciay's avatar
garciay committed
186
  }
garciay's avatar
garciay committed
187

garciay's avatar
garciay committed
188
189
190
191
192
  /****************************************************
   * @desc    External function to decode a GeoNetworkingPdu type
   * @param   value to encode
   * @return  encoded value
   ****************************************************/
garciay's avatar
garciay committed
193

garciay's avatar
garciay committed
194
195
196
  INTEGER fx__dec__GeoNetworkingPdu(BITSTRING& b, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p)
  {
    loggers::get_instance().log(">>> fx__dec__GeoNetworkingPdu");
garciay's avatar
garciay committed
197
198
199
    GeoNetworkingCodec codec;
    OCTETSTRING is = bit2oct(b);

garciay's avatar
garciay committed
200
201
202
    if (codec.decode(OCTETSTRING(is.lengthof(), static_cast<const unsigned char *>(is)), p) == -1) {
      loggers::get_instance().warning("fx__dec__GeoNetworkingPdu: -1 result code was returned");
      return -1;
garciay's avatar
garciay committed
203
    }
garciay's avatar
garciay committed
204
    
garciay's avatar
garciay committed
205
    return 0;
garciay's avatar
garciay committed
206
207
208
209
210
211
212
213
214
215
  }

  /****************************************************
   * @desc    External function to encode a Payload type
   * @param   value to encode
   * @return  encoded value
   ****************************************************/
  BITSTRING fx__enc__Payload(const LibItsGeoNetworking__TypesAndValues::Payload& p)
  {
    loggers::get_instance().log("fx__enc__Payload");
garciay's avatar
garciay committed
216
    return int2bit(0,8);
garciay's avatar
garciay committed
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
  }

  /****************************************************
   * @desc    External function to decode a Payload type
   * @param   value to encode
   * @return  encoded value
   ****************************************************/

  INTEGER fx__dec__Payload(BITSTRING& b, LibItsGeoNetworking__TypesAndValues::Payload& p)
  {
    return -1;
  }

  /****************************************************
   * @desc    External function to encode a GnNonSecuredPacket type
   * @param   value to encode
   * @return  encoded value
   ****************************************************/
  BITSTRING fx__enc__GnNonSecuredPacket(const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket& p)
  {
garciay's avatar
garciay committed
237
    return int2bit(0,8);
garciay's avatar
garciay committed
238
239
240
241
242
243
244
245
246
247
248
249
  }

  /****************************************************
   * @desc    External function to decode a GnNonSecuredPacket type
   * @param   value to encode
   * @return  encoded value
   ****************************************************/

  INTEGER fx__dec__GnNonSecuredPacket(BITSTRING& b, LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket& p)
  {
    return -1;
  }
250
251

} //end namespace