-
Notifications
You must be signed in to change notification settings - Fork 56
/
ie.go
682 lines (613 loc) · 30.5 KB
/
ie.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
// Copyright 2019-2024 go-pfcp authors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
package ie
import (
"encoding/binary"
"io"
"time"
"github.com/wmnsk/go-pfcp/internal/logger"
"github.com/wmnsk/go-pfcp/internal/utils"
)
// IE Type definitions.
const (
_ uint16 = 0
CreatePDR uint16 = 1
PDI uint16 = 2
CreateFAR uint16 = 3
ForwardingParameters uint16 = 4
DuplicatingParameters uint16 = 5
CreateURR uint16 = 6
CreateQER uint16 = 7
CreatedPDR uint16 = 8
UpdatePDR uint16 = 9
UpdateFAR uint16 = 10
UpdateForwardingParameters uint16 = 11
UpdateBARWithinSessionReportResponse uint16 = 12
UpdateURR uint16 = 13
UpdateQER uint16 = 14
RemovePDR uint16 = 15
RemoveFAR uint16 = 16
RemoveURR uint16 = 17
RemoveQER uint16 = 18
Cause uint16 = 19
SourceInterface uint16 = 20
FTEID uint16 = 21
NetworkInstance uint16 = 22
SDFFilter uint16 = 23
ApplicationID uint16 = 24
GateStatus uint16 = 25
MBR uint16 = 26
GBR uint16 = 27
QERCorrelationID uint16 = 28
Precedence uint16 = 29
TransportLevelMarking uint16 = 30
VolumeThreshold uint16 = 31
TimeThreshold uint16 = 32
MonitoringTime uint16 = 33
SubsequentVolumeThreshold uint16 = 34
SubsequentTimeThreshold uint16 = 35
InactivityDetectionTime uint16 = 36
ReportingTriggers uint16 = 37
RedirectInformation uint16 = 38
ReportType uint16 = 39
OffendingIE uint16 = 40
ForwardingPolicy uint16 = 41
DestinationInterface uint16 = 42
UPFunctionFeatures uint16 = 43
ApplyAction uint16 = 44
DownlinkDataServiceInformation uint16 = 45
DownlinkDataNotificationDelay uint16 = 46
DLBufferingDuration uint16 = 47
DLBufferingSuggestedPacketCount uint16 = 48
PFCPSMReqFlags uint16 = 49
PFCPSRRspFlags uint16 = 50
LoadControlInformation uint16 = 51
SequenceNumber uint16 = 52
Metric uint16 = 53
OverloadControlInformation uint16 = 54
Timer uint16 = 55
PDRID uint16 = 56
FSEID uint16 = 57
ApplicationIDsPFDs uint16 = 58
PFDContext uint16 = 59
NodeID uint16 = 60
PFDContents uint16 = 61
MeasurementMethod uint16 = 62
UsageReportTrigger uint16 = 63
MeasurementPeriod uint16 = 64
FQCSID uint16 = 65
VolumeMeasurement uint16 = 66
DurationMeasurement uint16 = 67
ApplicationDetectionInformation uint16 = 68
TimeOfFirstPacket uint16 = 69
TimeOfLastPacket uint16 = 70
QuotaHoldingTime uint16 = 71
DroppedDLTrafficThreshold uint16 = 72
VolumeQuota uint16 = 73
TimeQuota uint16 = 74
StartTime uint16 = 75
EndTime uint16 = 76
QueryURR uint16 = 77
UsageReportWithinSessionModificationResponse uint16 = 78
UsageReportWithinSessionDeletionResponse uint16 = 79
UsageReportWithinSessionReportRequest uint16 = 80
URRID uint16 = 81
LinkedURRID uint16 = 82
DownlinkDataReport uint16 = 83
OuterHeaderCreation uint16 = 84
CreateBAR uint16 = 85
UpdateBARWithinSessionModificationRequest uint16 = 86
RemoveBAR uint16 = 87
BARID uint16 = 88
CPFunctionFeatures uint16 = 89
UsageInformation uint16 = 90
ApplicationInstanceID uint16 = 91
FlowInformation uint16 = 92
UEIPAddress uint16 = 93
PacketRate uint16 = 94
OuterHeaderRemoval uint16 = 95
RecoveryTimeStamp uint16 = 96
DLFlowLevelMarking uint16 = 97
HeaderEnrichment uint16 = 98
ErrorIndicationReport uint16 = 99
MeasurementInformation uint16 = 100
NodeReportType uint16 = 101
UserPlanePathFailureReport uint16 = 102
RemoteGTPUPeer uint16 = 103
URSEQN uint16 = 104
UpdateDuplicatingParameters uint16 = 105
ActivatePredefinedRules uint16 = 106
DeactivatePredefinedRules uint16 = 107
FARID uint16 = 108
QERID uint16 = 109
OCIFlags uint16 = 110
PFCPAssociationReleaseRequest uint16 = 111
GracefulReleasePeriod uint16 = 112
PDNType uint16 = 113
FailedRuleID uint16 = 114
TimeQuotaMechanism uint16 = 115
UserPlaneIPResourceInformation uint16 = 116
UserPlaneInactivityTimer uint16 = 117
AggregatedURRs uint16 = 118
Multiplier uint16 = 119
AggregatedURRID uint16 = 120
SubsequentVolumeQuota uint16 = 121
SubsequentTimeQuota uint16 = 122
RQI uint16 = 123
QFI uint16 = 124
QueryURRReference uint16 = 125
AdditionalUsageReportsInformation uint16 = 126
CreateTrafficEndpoint uint16 = 127
CreatedTrafficEndpoint uint16 = 128
UpdateTrafficEndpoint uint16 = 129
RemoveTrafficEndpoint uint16 = 130
TrafficEndpointID uint16 = 131
EthernetPacketFilter uint16 = 132
MACAddress uint16 = 133
CTAG uint16 = 134
STAG uint16 = 135
Ethertype uint16 = 136
Proxying uint16 = 137
EthernetFilterID uint16 = 138
EthernetFilterProperties uint16 = 139
SuggestedBufferingPacketsCount uint16 = 140
UserID uint16 = 141
EthernetPDUSessionInformation uint16 = 142
EthernetTrafficInformation uint16 = 143
MACAddressesDetected uint16 = 144
MACAddressesRemoved uint16 = 145
EthernetInactivityTimer uint16 = 146
AdditionalMonitoringTime uint16 = 147
EventQuota uint16 = 148
EventThreshold uint16 = 149
SubsequentEventQuota uint16 = 150
SubsequentEventThreshold uint16 = 151
TraceInformation uint16 = 152
FramedRoute uint16 = 153
FramedRouting uint16 = 154
FramedIPv6Route uint16 = 155
EventTimeStamp uint16 = 156
AveragingWindow uint16 = 157
PagingPolicyIndicator uint16 = 158
APNDNN uint16 = 159
TGPPInterfaceType uint16 = 160
PFCPSRReqFlags uint16 = 161
PFCPAUReqFlags uint16 = 162
ActivationTime uint16 = 163
DeactivationTime uint16 = 164
CreateMAR uint16 = 165
TGPPAccessForwardingActionInformation uint16 = 166
NonTGPPAccessForwardingActionInformation uint16 = 167
RemoveMAR uint16 = 168
UpdateMAR uint16 = 169
MARID uint16 = 170
SteeringFunctionality uint16 = 171
SteeringMode uint16 = 172
Weight uint16 = 173
Priority uint16 = 174
UpdateTGPPAccessForwardingActionInformation uint16 = 175
UpdateNonTGPPAccessForwardingActionInformation uint16 = 176
UEIPAddressPoolIdentity uint16 = 177
AlternativeSMFIPAddress uint16 = 178
PacketReplicationAndDetectionCarryOnInformation uint16 = 179
SMFSetID uint16 = 180
QuotaValidityTime uint16 = 181
NumberOfReports uint16 = 182
PFCPSessionRetentionInformation uint16 = 183
PFCPASRspFlags uint16 = 184
CPPFCPEntityIPAddress uint16 = 185
PFCPSEReqFlags uint16 = 186
UserPlanePathRecoveryReport uint16 = 187
IPMulticastAddressingInfo uint16 = 188
JoinIPMulticastInformationWithinUsageReport uint16 = 189
LeaveIPMulticastInformationWithinUsageReport uint16 = 190
IPMulticastAddress uint16 = 191
SourceIPAddress uint16 = 192
PacketRateStatus uint16 = 193
CreateBridgeInfoForTSC uint16 = 194
CreatedBridgeInfoForTSC uint16 = 195
DSTTPortNumber uint16 = 196
NWTTPortNumber uint16 = 197
TSNBridgeID uint16 = 198
TSCManagementInformationWithinSessionModificationRequest uint16 = 199
TSCManagementInformationWithinSessionModificationResponse uint16 = 200
TSCManagementInformationWithinSessionReportRequest uint16 = 201
PortManagementInformationForTSCWithinSessionModificationRequest uint16 = 199 // Deprecated
PortManagementInformationForTSCWithinSessionModificationResponse uint16 = 200 // Deprecated
PortManagementInformationForTSCWithinSessionReportRequest uint16 = 201 // Deprecated
PortManagementInformationContainer uint16 = 202
ClockDriftControlInformation uint16 = 203
RequestedClockDriftInformation uint16 = 204
ClockDriftReport uint16 = 205
TSNTimeDomainNumber uint16 = 206
TimeOffsetThreshold uint16 = 207
CumulativeRateRatioThreshold uint16 = 208
TimeOffsetMeasurement uint16 = 209
CumulativeRateRatioMeasurement uint16 = 210
RemoveSRR uint16 = 211
CreateSRR uint16 = 212
UpdateSRR uint16 = 213
SessionReport uint16 = 214
SRRID uint16 = 215
AccessAvailabilityControlInformation uint16 = 216
RequestedAccessAvailabilityInformation uint16 = 217
AccessAvailabilityReport uint16 = 218
AccessAvailabilityInformation uint16 = 219
ProvideATSSSControlInformation uint16 = 220
ATSSSControlParameters uint16 = 221
MPTCPControlInformation uint16 = 222
ATSSSLLControlInformation uint16 = 223
PMFControlInformation uint16 = 224
MPTCPParameters uint16 = 225
ATSSSLLParameters uint16 = 226
PMFParameters uint16 = 227
MPTCPAddressInformation uint16 = 228
UELinkSpecificIPAddress uint16 = 229
PMFAddressInformation uint16 = 230
ATSSSLLInformation uint16 = 231
DataNetworkAccessIdentifier uint16 = 232
UEIPAddressPoolInformation uint16 = 233
AveragePacketDelay uint16 = 234
MinimumPacketDelay uint16 = 235
MaximumPacketDelay uint16 = 236
QoSReportTrigger uint16 = 237
GTPUPathQoSControlInformation uint16 = 238
GTPUPathQoSReport uint16 = 239
QoSInformationInGTPUPathQoSReport uint16 = 240
GTPUPathInterfaceType uint16 = 241
QoSMonitoringPerQoSFlowControlInformation uint16 = 242
RequestedQoSMonitoring uint16 = 243
ReportingFrequency uint16 = 244
PacketDelayThresholds uint16 = 245
MinimumWaitTime uint16 = 246
QoSMonitoringReport uint16 = 247
QoSMonitoringMeasurement uint16 = 248
MTEDTControlInformation uint16 = 249
DLDataPacketsSize uint16 = 250
QERControlIndications uint16 = 251
PacketRateStatusReport uint16 = 252
NFInstanceID uint16 = 253
EthernetContextInformation uint16 = 254
RedundantTransmissionParameters uint16 = 255
UpdatedPDR uint16 = 256
SNSSAI uint16 = 257
IPVersion uint16 = 258
PFCPASReqFlags uint16 = 259
DataStatus uint16 = 260
ProvideRDSConfigurationInformation uint16 = 261
RDSConfigurationInformation uint16 = 262
QueryPacketRateStatusWithinSessionModificationRequest uint16 = 263
PacketRateStatusReportWithinSessionModificationResponse uint16 = 264
MPTCPApplicableIndication uint16 = 265
BridgeManagementInformationContainer uint16 = 266
UEIPAddressUsageInformation uint16 = 267
NumberOfUEIPAddresses uint16 = 268
ValidityTimer uint16 = 269
RedundantTransmissionForwardingParameters uint16 = 270
TransportDelayReporting uint16 = 271
)
// IE represents an Information Element of PFCP messages.
type IE struct {
Type uint16
Length uint16
EnterpriseID uint16
Payload []byte
ChildIEs []*IE
}
// New creates a new IE.
func New(itype uint16, data []byte) *IE {
i := &IE{
Type: itype,
Payload: data,
}
i.SetLength()
return i
}
// NewVendorSpecificIE creates a new vendor-specific IE.
func NewVendorSpecificIE(itype, eid uint16, data []byte) *IE {
i := &IE{
Type: itype,
EnterpriseID: eid,
Payload: data,
}
i.SetLength()
return i
}
// NewGroupedIE creates a new grouped IE.
func NewGroupedIE(itype uint16, ies ...*IE) *IE {
return newGroupedIE(itype, 0, ies...)
}
// NewVendorSpecificGroupedIE creates a new grouped IE.
func NewVendorSpecificGroupedIE(itype, eid uint16, ies ...*IE) *IE {
return newGroupedIE(itype, eid, ies...)
}
// NewUint8ValIE creates a new IE with uint8 value.
func NewUint8IE(itype uint16, v uint8) *IE {
return newUint8ValIE(itype, v)
}
// NewUint16ValIE creates a new IE with uint16 value.
func NewUint16IE(itype uint16, v uint16) *IE {
return newUint16ValIE(itype, v)
}
// NewUint32ValIE creates a new IE with uint32 value.
func NewUint32IE(itype uint16, v uint32) *IE {
return newUint32ValIE(itype, v)
}
// NewUint64ValIE creates a new IE with uint64 value.
func NewUint64IE(itype uint16, v uint64) *IE {
return newUint64ValIE(itype, v)
}
// NewStringIE creates a new IE with string value.
func NewStringIE(itype uint16, v string) *IE {
return newStringIE(itype, v)
}
// NewFQDNIE creates a new IE with FQDN value.
func NewFQDNIE(itype uint16, v string) *IE {
return newFQDNIE(itype, v)
}
// ValueAsUint8 returns the value of IE as uint8.
func (i *IE) ValueAsUint8() (uint8, error) {
if i.IsGrouped() {
return 0, &InvalidTypeError{Type: i.Type}
}
if len(i.Payload) < 1 {
return 0, io.ErrUnexpectedEOF
}
return i.Payload[0], nil
}
// ValueAsUint16 returns the value of IE as uint16.
func (i *IE) ValueAsUint16() (uint16, error) {
if i.IsGrouped() {
return 0, &InvalidTypeError{Type: i.Type}
}
if len(i.Payload) < 2 {
return 0, io.ErrUnexpectedEOF
}
return binary.BigEndian.Uint16(i.Payload[0:2]), nil
}
// ValueAsUint32 returns the value of IE as uint32.
func (i *IE) ValueAsUint32() (uint32, error) {
if i.IsGrouped() {
return 0, &InvalidTypeError{Type: i.Type}
}
if len(i.Payload) < 4 {
return 0, io.ErrUnexpectedEOF
}
return binary.BigEndian.Uint32(i.Payload[0:4]), nil
}
// ValueAsUint64 returns the value of IE as uint64.
func (i *IE) ValueAsUint64() (uint64, error) {
if i.IsGrouped() {
return 0, &InvalidTypeError{Type: i.Type}
}
if len(i.Payload) < 8 {
return 0, io.ErrUnexpectedEOF
}
return binary.BigEndian.Uint64(i.Payload[0:8]), nil
}
// ValueAsString returns the value of IE as string.
func (i *IE) ValueAsString() (string, error) {
if i.IsGrouped() {
return "", &InvalidTypeError{Type: i.Type}
}
return string(i.Payload), nil
}
// ValueAsFQDN returns the value of IE as string, decoded as FQDN.
func (i *IE) ValueAsFQDN() (string, error) {
if i.IsGrouped() {
return "", &InvalidTypeError{Type: i.Type}
}
return utils.DecodeFQDN(i.Payload), nil
}
// ValueAsGrouped returns the value of IE as grouped IE.
//
// This method returns the ChildIEs field if it is already parsed.
// Otherwise, it parses the Payload field and returns the result.
//
// It is recommended to access the ChildIEs field directly if you know the payload is
// already parsed and not modified. If you need to parse the payload anyway, use the
// `<IE-Name>()` method instead, which disregards the ChildIEs field.
//
// For vendor-specific IE, this method tries to parse as grouped IE. If it fails, it
// returns error.
func (i *IE) ValueAsGrouped() ([]*IE, error) {
if !(i.IsGrouped() || i.IsVendorSpecific()) {
return nil, &InvalidTypeError{Type: i.Type}
}
if len(i.ChildIEs) < 1 {
return ParseMultiIEs(i.Payload)
}
return i.ChildIEs, nil
}
// valueAs3GPPTimestamp returns the value of IE as time.Time, in the format of
// timestamp IEs defined in 3GPP TS 29.244 as follows:
//
// "a UTC time. Octets 5 to 8 shall be encoded in the same format as the first four octets
// of the 64-bit timestamp format as defined in clause 6 of IETF RFC 5905 [12].
// NOTE: The encoding is defined as the time in seconds relative to 00:00:00 on 1 January 1900."
func (i *IE) valueAs3GPPTimestamp() (time.Time, error) {
if i.IsGrouped() {
return time.Time{}, &InvalidTypeError{Type: i.Type}
}
if len(i.Payload) < 4 {
return time.Time{}, io.ErrUnexpectedEOF
}
return time.Unix(int64(binary.BigEndian.Uint32(i.Payload[0:4])-2208988800), 0), nil
}
// Parse parses b into IE.
//
// Note that this function uses the given bytes directly, so not safe to use
// the buffer after calling this function. When you use the buffer somewhere
// else, copy it before calling this function.
func Parse(b []byte) (*IE, error) {
i := &IE{}
if err := i.UnmarshalBinary(b); err != nil {
return nil, err
}
return i, nil
}
// ParseMultiIEs decodes multiple IEs at a time.
// This is easy and useful but slower than decoding one by one.
// When you don't know the number of IEs, this is the only way to decode them.
// See benchmarks in diameter_test.go for the detail.
//
// Note that this function uses the given bytes directly, so not safe to use
// the buffer after calling this function. When you use the buffer somewhere
// else, copy it before calling this function.
func ParseMultiIEs(b []byte) ([]*IE, error) {
var ies []*IE
for {
if len(b) == 0 {
break
}
i, err := Parse(b)
if err != nil {
return nil, err
}
ies = append(ies, i)
b = b[i.MarshalLen():]
}
return ies, nil
}
// UnmarshalBinary parses b into IE.
func (i *IE) UnmarshalBinary(b []byte) error {
l := len(b)
if l < 4 {
return io.ErrUnexpectedEOF
}
i.Type = binary.BigEndian.Uint16(b[0:2])
i.Length = binary.BigEndian.Uint16(b[2:4])
offset := 4
end := int(i.Length)
if i.IsVendorSpecific() {
if l < 6 {
return io.ErrUnexpectedEOF
}
if end < 2 {
return ErrInvalidLength
}
i.EnterpriseID = binary.BigEndian.Uint16(b[4:6])
offset += 2
end -= 2
}
if l <= offset {
return nil
}
if l < offset+end {
return io.ErrUnexpectedEOF
}
i.Payload = b[offset : offset+end]
if i.IsGrouped() {
var err error
i.ChildIEs, err = ParseMultiIEs(i.Payload)
if err != nil {
return err
}
}
return nil
}
// Marshal returns the byte sequence generated from an IE instance.
func (i *IE) Marshal() ([]byte, error) {
b := make([]byte, i.MarshalLen())
if err := i.MarshalTo(b); err != nil {
return nil, err
}
return b, nil
}
// MarshalTo puts the byte sequence in the byte array given as b.
func (i *IE) MarshalTo(b []byte) error {
l := len(b)
if l < 4 {
return ErrInvalidLength
}
binary.BigEndian.PutUint16(b[:2], i.Type)
binary.BigEndian.PutUint16(b[2:4], i.Length)
offset := 4
if i.IsVendorSpecific() && l >= 6 {
binary.BigEndian.PutUint16(b[4:6], i.EnterpriseID)
offset += 2
}
if i.IsGrouped() {
for _, ie := range i.ChildIEs {
if err := ie.MarshalTo(b[offset:]); err != nil {
return err
}
offset += ie.MarshalLen()
}
return nil
}
copy(b[offset:i.MarshalLen()], i.Payload)
return nil
}
// MarshalLen returns field length in integer.
func (i *IE) MarshalLen() int {
l := 4
if i.IsVendorSpecific() {
l += 2
}
if i.IsGrouped() {
for _, ie := range i.ChildIEs {
l += ie.MarshalLen()
}
return l
}
return l + len(i.Payload)
}
// SetLength sets the length in Length field.
func (i *IE) SetLength() {
l := 0
if i.IsVendorSpecific() {
l += 2
}
i.Length = uint16(l + len(i.Payload))
}
// IsVendorSpecific reports whether an IE is vendor-specific or defined by 3gpp.
func (i *IE) IsVendorSpecific() bool {
// Spef: TS 29.244 8.1.1 Information Element Format
// If the Bit 8 of Octet 1 is not set, this indicates that the IE is defined by 3GPP
// and the EnterpriseID is absent. If Bit 8 of Octet 1 is set, this indicates that the
// IE is defined by a vendor and the Enterprise ID is present identified by the Enterprise ID.
return i.Type&0x8000 != 0
}
func newUint8ValIE(t uint16, v uint8) *IE {
return New(t, []byte{v})
}
func newUint16ValIE(t uint16, v uint16) *IE {
i := New(t, make([]byte, 2))
binary.BigEndian.PutUint16(i.Payload, v)
return i
}
func newUint32ValIE(t uint16, v uint32) *IE {
i := New(t, make([]byte, 4))
binary.BigEndian.PutUint32(i.Payload, v)
return i
}
func newUint64ValIE(t uint16, v uint64) *IE {
i := New(t, make([]byte, 8))
binary.BigEndian.PutUint64(i.Payload, v)
return i
}
func newStringIE(t uint16, v string) *IE {
return New(t, []byte(v))
}
func newFQDNIE(t uint16, v string) *IE {
return New(t, utils.EncodeFQDN(v))
}
func newGroupedIE(itype, eid uint16, ies ...*IE) *IE {
i := NewVendorSpecificIE(itype, eid, make([]byte, 0))
for _, ie := range ies {
if ie == nil {
continue
}
i.ChildIEs = append(i.ChildIEs, ie)
serialized, err := ie.Marshal()
if err != nil {
logger.Logf("newGroupedIE() failed to marshal an IE(Type=%d): %v", ie.Type, err)
return nil
}
i.Payload = append(i.Payload, serialized...)
}
i.SetLength()
return i
}