DPDK logo

Elixir Cross Referencer

  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
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2019 Intel Corporation

from scapy.all import *
import unittest
import pkttest

#{ipv4{ipv4}} test
SRC_ADDR_IPV4_1 = "192.168.1.1"
DST_ADDR_IPV4_1 = "192.168.2.1"

#{ipv6{ipv6}} test
SRC_ADDR_IPV6_1 = "1111:0000:0000:0000:0000:0000:0000:0001"
DST_ADDR_IPV6_1 = "2222:0000:0000:0000:0000:0000:0000:0001"

#{ipv4{ipv6}} test
SRC_ADDR_IPV4_2 = "192.168.11.1"
DST_ADDR_IPV4_2 = "192.168.12.1"
SRC_ADDR_IPV6_2 = "1111:0000:0000:0000:0000:0000:0001:0001"
DST_ADDR_IPV6_2 = "2222:0000:0000:0000:0000:0000:0001:0001"

#{ipv6{ipv4}} test
SRC_ADDR_IPV4_3 = "192.168.21.1"
DST_ADDR_IPV4_3 = "192.168.22.1"
SRC_ADDR_IPV6_3 = "1111:0000:0000:0000:0000:0001:0001:0001"
DST_ADDR_IPV6_3 = "2222:0000:0000:0000:0000:0001:0001:0001"

def config():
    return """
#outter-ipv4 inner-ipv4 tunnel mode test
sp ipv4 out esp protect 5 pri 1 \\
src {0}/32 \\
dst {1}/32 \\
sport 0:65535 dport 0:65535

sp ipv4 in esp protect 6 pri 1 \\
src {1}/32 \\
dst {0}/32 \\
sport 0:65535 dport 0:65535

sa out 5 cipher_algo null auth_algo null mode ipv4-tunnel \\
src {0} dst {1}
sa in 6 cipher_algo null auth_algo null mode ipv4-tunnel \\
src {1} dst {0}

rt ipv4 dst {0}/32 port 1
rt ipv4 dst {1}/32 port 0

#outter-ipv6 inner-ipv6 tunnel mode test
sp ipv6 out esp protect 7 pri 1 \\
src {2}/128 \\
dst {3}/128 \\
sport 0:65535 dport 0:65535

sp ipv6 in esp protect 8 pri 1 \\
src {3}/128 \\
dst {2}/128 \\
sport 0:65535 dport 0:65535

sa out 7 cipher_algo null auth_algo null mode ipv6-tunnel \\
src {2} dst {3}
sa in 8 cipher_algo null auth_algo null mode ipv6-tunnel \\
src {3} dst {2}

rt ipv6 dst {2}/128 port 1
rt ipv6 dst {3}/128 port 0

#outter-ipv4 inner-ipv6 tunnel mode test
sp ipv6 out esp protect 9 pri 1 \\
src {4}/128 \\
dst {5}/128 \\
sport 0:65535 dport 0:65535

sp ipv6 in esp protect 10 pri 1 \\
src {5}/128 \\
dst {4}/128 \\
sport 0:65535 dport 0:65535

sa out 9 cipher_algo null auth_algo null mode ipv4-tunnel \\
src {6} dst {7}
sa in 10 cipher_algo null auth_algo null mode ipv4-tunnel \\
src {7} dst {6}

rt ipv6 dst {4}/128 port 1
rt ipv4 dst {7}/32 port 0

#outter-ipv6 inner-ipv4 tunnel mode test
sp ipv4 out esp protect 11 pri 1 \\
src {8}/32 \\
dst {9}/32 \\
sport 0:65535 dport 0:65535

sp ipv4 in esp protect 12 pri 1 \\
src {9}/32 \\
dst {8}/32 \\
sport 0:65535 dport 0:65535

sa out 11 cipher_algo null auth_algo null mode ipv6-tunnel \\
src {10} dst {11}
sa in 12 cipher_algo null auth_algo null mode ipv6-tunnel \\
src {11} dst {10}

rt ipv4 dst {8}/32 port 1
rt ipv6 dst {11}/128 port 0
""".format(SRC_ADDR_IPV4_1, DST_ADDR_IPV4_1,
           SRC_ADDR_IPV6_1, DST_ADDR_IPV6_1,
           SRC_ADDR_IPV6_2, DST_ADDR_IPV6_2, SRC_ADDR_IPV4_2, DST_ADDR_IPV4_2,
           SRC_ADDR_IPV4_3, DST_ADDR_IPV4_3, SRC_ADDR_IPV6_3, DST_ADDR_IPV6_3)

ECN_ECT0    = 0x02
ECN_ECT1    = 0x01
ECN_CE      = 0x03
DSCP_1      = 0x04
DSCP_3F     = 0xFC

class TestTunnelHeaderReconstruct(unittest.TestCase):
    def setUp(self):
        self.px = pkttest.PacketXfer()
        th = IP(src=DST_ADDR_IPV4_1, dst=SRC_ADDR_IPV4_1)
        self.sa_ipv4v4 = SecurityAssociation(ESP, spi=6, tunnel_header = th)

        th = IPv6(src=DST_ADDR_IPV6_1, dst=SRC_ADDR_IPV6_1)
        self.sa_ipv6v6 = SecurityAssociation(ESP, spi=8, tunnel_header = th)

        th = IP(src=DST_ADDR_IPV4_2, dst=SRC_ADDR_IPV4_2)
        self.sa_ipv4v6 = SecurityAssociation(ESP, spi=10, tunnel_header = th)

        th = IPv6(src=DST_ADDR_IPV6_3, dst=SRC_ADDR_IPV6_3)
        self.sa_ipv6v4 = SecurityAssociation(ESP, spi=12, tunnel_header = th)

    def gen_pkt_plain_ipv4(self, src, dst, tos):
        pkt = IP(src=src, dst=dst, tos=tos)
        pkt /= UDP(sport=123,dport=456)/Raw(load="abc")
        return pkt

    def gen_pkt_plain_ipv6(self, src, dst, tc):
        pkt = IPv6(src=src, dst=dst, tc=tc)
        pkt /= UDP(sport=123,dport=456)/Raw(load="abc")
        return pkt

    def gen_pkt_tun_ipv4v4(self, tos_outter, tos_inner):
        pkt = self.gen_pkt_plain_ipv4(DST_ADDR_IPV4_1, SRC_ADDR_IPV4_1,
                                      tos_inner)
        pkt = self.sa_ipv4v4.encrypt(pkt)
        self.assertEqual(pkt[IP].proto, socket.IPPROTO_ESP)
        self.assertEqual(pkt[ESP].spi, 6)
        pkt[IP].tos = tos_outter
        return pkt

    def gen_pkt_tun_ipv6v6(self, tc_outter, tc_inner):
        pkt = self.gen_pkt_plain_ipv6(DST_ADDR_IPV6_1, SRC_ADDR_IPV6_1,
                                      tc_inner)
        pkt = self.sa_ipv6v6.encrypt(pkt)
        self.assertEqual(pkt[IPv6].nh, socket.IPPROTO_ESP)
        self.assertEqual(pkt[ESP].spi, 8)
        pkt[IPv6].tc = tc_outter
        return pkt

    def gen_pkt_tun_ipv4v6(self, tos_outter, tc_inner):
        pkt = self.gen_pkt_plain_ipv6(DST_ADDR_IPV6_2, SRC_ADDR_IPV6_2,
                                      tc_inner)
        pkt = self.sa_ipv4v6.encrypt(pkt)
        self.assertEqual(pkt[IP].proto, socket.IPPROTO_ESP)
        self.assertEqual(pkt[ESP].spi, 10)
        pkt[IP].tos = tos_outter
        return pkt

    def gen_pkt_tun_ipv6v4(self, tc_outter, tos_inner):
        pkt = self.gen_pkt_plain_ipv4(DST_ADDR_IPV4_3, SRC_ADDR_IPV4_3,
                                      tos_inner)
        pkt = self.sa_ipv6v4.encrypt(pkt)
        self.assertEqual(pkt[IPv6].nh, socket.IPPROTO_ESP)
        self.assertEqual(pkt[ESP].spi, 12)
        pkt[IPv6].tc = tc_outter
        return pkt

#RFC4301 5.1.2.1 & 5.1.2.2, outbound packets shall be copied ECN field
    def test_outb_ipv4v4_ecn(self):
        pkt = self.gen_pkt_plain_ipv4(SRC_ADDR_IPV4_1, DST_ADDR_IPV4_1,
                                      ECN_ECT1)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_ESP)
        self.assertEqual(resp[ESP].spi, 5)
        self.assertEqual(resp[IP].tos, ECN_ECT1)

        pkt = self.gen_pkt_plain_ipv4(SRC_ADDR_IPV4_1, DST_ADDR_IPV4_1,
                                      ECN_ECT0)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_ESP)
        self.assertEqual(resp[ESP].spi, 5)
        self.assertEqual(resp[IP].tos, ECN_ECT0)

        pkt = self.gen_pkt_plain_ipv4(SRC_ADDR_IPV4_1, DST_ADDR_IPV4_1,
                                      ECN_CE)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_ESP)
        self.assertEqual(resp[ESP].spi, 5)
        self.assertEqual(resp[IP].tos, ECN_CE)

    def test_outb_ipv6v6_ecn(self):
        pkt = self.gen_pkt_plain_ipv6(SRC_ADDR_IPV6_1, DST_ADDR_IPV6_1,
                                      ECN_ECT1)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_ESP)
        self.assertEqual(resp[IPv6].tc, ECN_ECT1)

        pkt = self.gen_pkt_plain_ipv6(SRC_ADDR_IPV6_1, DST_ADDR_IPV6_1,
                                      ECN_ECT0)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_ESP)
        self.assertEqual(resp[ESP].spi, 7)
        self.assertEqual(resp[IPv6].tc, ECN_ECT0)

        pkt = self.gen_pkt_plain_ipv6(SRC_ADDR_IPV6_1, DST_ADDR_IPV6_1,
                                      ECN_CE)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_ESP)
        self.assertEqual(resp[ESP].spi, 7)
        self.assertEqual(resp[IPv6].tc, ECN_CE)

    def test_outb_ipv4v6_ecn(self):
        pkt = self.gen_pkt_plain_ipv6(SRC_ADDR_IPV6_2, DST_ADDR_IPV6_2,
                                      ECN_ECT1)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_ESP)
        self.assertEqual(resp[IP].tos, ECN_ECT1)

        pkt = self.gen_pkt_plain_ipv6(SRC_ADDR_IPV6_2, DST_ADDR_IPV6_2,
                                      ECN_ECT0)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_ESP)
        self.assertEqual(resp[IP].tos, ECN_ECT0)

        pkt = self.gen_pkt_plain_ipv6(SRC_ADDR_IPV6_2, DST_ADDR_IPV6_2,
                                      ECN_CE)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_ESP)
        self.assertEqual(resp[IP].tos, ECN_CE)

    def test_outb_ipv6v4_ecn(self):
        pkt = self.gen_pkt_plain_ipv4(SRC_ADDR_IPV4_3, DST_ADDR_IPV4_3,
                                      ECN_ECT1)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_ESP)
        self.assertEqual(resp[IPv6].tc, ECN_ECT1)

        pkt = self.gen_pkt_plain_ipv4(SRC_ADDR_IPV4_3, DST_ADDR_IPV4_3,
                                      ECN_ECT0)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_ESP)
        self.assertEqual(resp[IPv6].tc, ECN_ECT0)

        pkt = self.gen_pkt_plain_ipv4(SRC_ADDR_IPV4_3, DST_ADDR_IPV4_3,
                                      ECN_CE)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_ESP)
        self.assertEqual(resp[IPv6].tc, ECN_CE)

#RFC4301 5.1.2.1 & 5.1.2.2, if outbound packets ECN is CE (0x3), inbound packets
#ECN is overwritten to CE, otherwise no change

#Outter header not CE, Inner header should be no change
    def test_inb_ipv4v4_ecn_inner_no_change(self):
        pkt = self.gen_pkt_tun_ipv4v4(ECN_ECT1, ECN_ECT0)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_UDP)
        self.assertEqual(resp[IP].tos, ECN_ECT0)

        pkt = self.gen_pkt_tun_ipv4v4(ECN_ECT0, ECN_ECT1)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_UDP)
        self.assertEqual(resp[IP].tos, ECN_ECT1)

        pkt = self.gen_pkt_tun_ipv4v4(ECN_ECT1, ECN_CE)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_UDP)
        self.assertEqual(resp[IP].tos, ECN_CE)

    def test_inb_ipv6v6_ecn_inner_no_change(self):
        pkt = self.gen_pkt_tun_ipv6v6(ECN_ECT1, ECN_ECT0)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_UDP)
        self.assertEqual(resp[IPv6].tc, ECN_ECT0)

        pkt = self.gen_pkt_tun_ipv6v6(ECN_ECT0, ECN_ECT1)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_UDP)
        self.assertEqual(resp[IPv6].tc, ECN_ECT1)

        pkt = self.gen_pkt_tun_ipv6v6(ECN_ECT1, ECN_CE)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_UDP)
        self.assertEqual(resp[IPv6].tc, ECN_CE)

    def test_inb_ipv4v6_ecn_inner_no_change(self):
        pkt = self.gen_pkt_tun_ipv4v6(ECN_ECT1, ECN_ECT0)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_UDP)
        self.assertEqual(resp[IPv6].tc, ECN_ECT0)

        pkt = self.gen_pkt_tun_ipv4v6(ECN_ECT0, ECN_ECT1)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_UDP)
        self.assertEqual(resp[IPv6].tc, ECN_ECT1)

        pkt = self.gen_pkt_tun_ipv4v6(ECN_ECT1, ECN_CE)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_UDP)
        self.assertEqual(resp[IPv6].tc, ECN_CE)

    def test_inb_ipv6v4_ecn_inner_no_change(self):
        pkt = self.gen_pkt_tun_ipv6v4(ECN_ECT1, ECN_ECT0)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_UDP)
        self.assertEqual(resp[IP].tos, ECN_ECT0)

        pkt = self.gen_pkt_tun_ipv6v4(ECN_ECT0, ECN_ECT1)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_UDP)
        self.assertEqual(resp[IP].tos, ECN_ECT1)

        pkt = self.gen_pkt_tun_ipv6v4(ECN_ECT1, ECN_CE)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_UDP)
        self.assertEqual(resp[IP].tos, ECN_CE)

#Outter header CE, Inner header should be changed to CE
    def test_inb_ipv4v4_ecn_inner_change(self):
        pkt = self.gen_pkt_tun_ipv4v4(ECN_CE, ECN_ECT0)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_UDP)
        self.assertEqual(resp[IP].tos, ECN_CE)

        pkt = self.gen_pkt_tun_ipv4v4(ECN_CE, ECN_ECT1)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_UDP)
        self.assertEqual(resp[IP].tos, ECN_CE)

    def test_inb_ipv6v6_ecn_inner_change(self):
        pkt = self.gen_pkt_tun_ipv6v6(ECN_CE, ECN_ECT0)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_UDP)
        self.assertEqual(resp[IPv6].tc, ECN_CE)

        pkt = self.gen_pkt_tun_ipv6v6(ECN_CE, ECN_ECT1)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_UDP)
        self.assertEqual(resp[IPv6].tc, ECN_CE)

    def test_inb_ipv4v6_ecn_inner_change(self):
        pkt = self.gen_pkt_tun_ipv4v6(ECN_CE, ECN_ECT0)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_UDP)
        self.assertEqual(resp[IPv6].tc, ECN_CE)

        pkt = self.gen_pkt_tun_ipv4v6(ECN_CE, ECN_ECT1)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_UDP)
        self.assertEqual(resp[IPv6].tc, ECN_CE)

    def test_inb_ipv6v4_ecn_inner_change(self):
        pkt = self.gen_pkt_tun_ipv6v4(ECN_CE, ECN_ECT0)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_UDP)
        self.assertEqual(resp[IP].tos, ECN_CE)

        pkt = self.gen_pkt_tun_ipv6v4(ECN_CE, ECN_ECT1)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_UDP)
        self.assertEqual(resp[IP].tos, ECN_CE)

#RFC4301 5.1.2.1.5 Outer DS field should be copied from Inner DS field
    def test_outb_ipv4v4_dscp(self):
        pkt = self.gen_pkt_plain_ipv4(SRC_ADDR_IPV4_1, DST_ADDR_IPV4_1,
                                      DSCP_1)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_ESP)
        self.assertEqual(resp[ESP].spi, 5)
        self.assertEqual(resp[IP].tos, DSCP_1)

        pkt = self.gen_pkt_plain_ipv4(SRC_ADDR_IPV4_1, DST_ADDR_IPV4_1,
                                      DSCP_3F)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_ESP)
        self.assertEqual(resp[ESP].spi, 5)
        self.assertEqual(resp[IP].tos, DSCP_3F)

    def test_outb_ipv6v6_dscp(self):
        pkt = self.gen_pkt_plain_ipv6(SRC_ADDR_IPV6_1, DST_ADDR_IPV6_1,
                                      DSCP_1)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_ESP)
        self.assertEqual(resp[ESP].spi, 7)
        self.assertEqual(resp[IPv6].tc, DSCP_1)

        pkt = self.gen_pkt_plain_ipv6(SRC_ADDR_IPV6_1, DST_ADDR_IPV6_1,
                                      DSCP_3F)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_ESP)
        self.assertEqual(resp[ESP].spi, 7)
        self.assertEqual(resp[IPv6].tc, DSCP_3F)

    def test_outb_ipv4v6_dscp(self):
        pkt = self.gen_pkt_plain_ipv6(SRC_ADDR_IPV6_2, DST_ADDR_IPV6_2,
                                      DSCP_1)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_ESP)
        self.assertEqual(resp[ESP].spi, 9)
        self.assertEqual(resp[IP].tos, DSCP_1)

        pkt = self.gen_pkt_plain_ipv6(SRC_ADDR_IPV6_2, DST_ADDR_IPV6_2,
                                      DSCP_3F)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_ESP)
        self.assertEqual(resp[ESP].spi, 9)
        self.assertEqual(resp[IP].tos, DSCP_3F)

    def test_outb_ipv6v4_dscp(self):
        pkt = self.gen_pkt_plain_ipv4(SRC_ADDR_IPV4_3, DST_ADDR_IPV4_3,
                                      DSCP_1)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_ESP)
        self.assertEqual(resp[ESP].spi, 11)
        self.assertEqual(resp[IPv6].tc, DSCP_1)

        pkt = self.gen_pkt_plain_ipv4(SRC_ADDR_IPV4_3, DST_ADDR_IPV4_3,
                                      DSCP_3F)
        resp = self.px.xfer_unprotected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_ESP)
        self.assertEqual(resp[ESP].spi, 11)
        self.assertEqual(resp[IPv6].tc, DSCP_3F)

#RFC4301 5.1.2.1.5 Inner DS field should not be affected by Outer DS field
    def test_inb_ipv4v4_dscp(self):
        pkt = self.gen_pkt_tun_ipv4v4(DSCP_3F, DSCP_1)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_UDP)
        self.assertEqual(resp[IP].tos, DSCP_1)

        pkt = self.gen_pkt_tun_ipv4v4(DSCP_1, DSCP_3F)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_UDP)
        self.assertEqual(resp[IP].tos, DSCP_3F)

    def test_inb_ipv6v6_dscp(self):
        pkt = self.gen_pkt_tun_ipv6v6(DSCP_3F, DSCP_1)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_UDP)
        self.assertEqual(resp[IPv6].tc, DSCP_1)

        pkt = self.gen_pkt_tun_ipv6v6(DSCP_1, DSCP_3F)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_UDP)
        self.assertEqual(resp[IPv6].tc, DSCP_3F)

    def test_inb_ipv4v6_dscp(self):
        pkt = self.gen_pkt_tun_ipv4v6(DSCP_3F, DSCP_1)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_UDP)
        self.assertEqual(resp[IPv6].tc, DSCP_1)

        pkt = self.gen_pkt_tun_ipv4v6(DSCP_1, DSCP_3F)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IPv6].nh, socket.IPPROTO_UDP)
        self.assertEqual(resp[IPv6].tc, DSCP_3F)

    def test_inb_ipv6v4_dscp(self):
        pkt = self.gen_pkt_tun_ipv6v4(DSCP_3F, DSCP_1)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_UDP)
        self.assertEqual(resp[IP].tos, DSCP_1)

        pkt = self.gen_pkt_tun_ipv6v4(DSCP_1, DSCP_3F)
        resp = self.px.xfer_protected(pkt)
        self.assertEqual(resp[IP].proto, socket.IPPROTO_UDP)
        self.assertEqual(resp[IP].tos, DSCP_3F)

pkttest.pkttest()