summaryrefslogtreecommitdiff
path: root/test/regression/mdns_test/mdns_query_rr_timeout_test.c
blob: cd78b14291b0cfc3257ebf0639c8a49160a06bd3 (plain)
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
/***************************************************************************/
/* Copyright (c) 2024 Microsoft Corporation                                */
/* Copyright (c) 2026 Eclipse ThreadX contributors                         */
/*                                                                         */
/* This program and the accompanying materials are made available under    */
/* the terms of the MIT License which is available at                      */
/* https://opensource.org/licenses/MIT.                                    */
/*                                                                         */
/* SPDX-License-Identifier: MIT                                            */
/***************************************************************************/


#include "nx_api.h"

#ifdef __PRODUCT_NETXDUO__

#include "netx_mdns_test.h"

/* Frame (75 bytes) */
static const unsigned char pkt1[75] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb, 0x00, 0x11, /* ..^..... */
0x22, 0x33, 0x44, 0x57, 0x08, 0x00, 0x45, 0x00, /* "3DW..E. */
0x00, 0x3d, 0x00, 0x02, 0x40, 0x00, 0xff, 0x11, /* .=..@... */
0x90, 0x93, 0x0a, 0x00, 0x00, 0x1f, 0xe0, 0x00, /* ........ */
0x00, 0xfb, 0x14, 0xe9, 0x14, 0xe9, 0x00, 0x29, /* .......) */
0x66, 0xba, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* f....... */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x5f, /* ......._ */
0x69, 0x70, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, /* ipp._tcp */
0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, /* .local.. */
0x0c, 0x00, 0x01                                /* ... */
};

/* Frame (276 bytes) */
static const unsigned char pkt2[276] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb, 0x00, 0x11, /* ..^..... */ 
0x22, 0x33, 0x44, 0x56, 0x08, 0x00, 0x45, 0x00, /* "3DV..E. */
0x01, 0x06, 0x00, 0x07, 0x40, 0x00, 0xff, 0x11, /* ....@... */
0xd9, 0x1c, 0xc0, 0xa8, 0x00, 0x1f, 0xe0, 0x00, /* ........ */
0x00, 0xfb, 0x14, 0xe9, 0x14, 0xe9, 0x00, 0xf2, /* ........ */
0x15, 0xc4, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x04, 0x5f, /* ......._ */
0x69, 0x70, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, /* ipp._tcp */
0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, /* .local.. */
0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, /* ......x. */
0x23, 0x11, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, /* #.Simple */
0x20, 0x57, 0x65, 0x62, 0x20, 0x53, 0x65, 0x72, /*  Web Ser */
0x76, 0x65, 0x72, 0x04, 0x5f, 0x69, 0x70, 0x70, /* ver._ipp */
0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, 0x6f, /* ._tcp.lo */
0x63, 0x61, 0x6c, 0x00, 0x11, 0x53, 0x69, 0x6d, /* cal..Sim */
0x70, 0x6c, 0x65, 0x20, 0x57, 0x65, 0x62, 0x20, /* ple Web  */
0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x04, 0x5f, /* Server._ */
0x69, 0x70, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, /* ipp._tcp */
0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, /* .local.. */
0x21, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, /* !.....x. */
0x15, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x90, 0x07, /* ........ */
0x75, 0x62, 0x75, 0x6e, 0x74, 0x75, 0x31, 0x05, /* ubuntu1. */
0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x11, 0x53, /* local..S */ 
0x69, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x57, 0x65, /* imple We */
0x62, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, /* b Server */ 
0x04, 0x5f, 0x69, 0x70, 0x70, 0x04, 0x5f, 0x74, /* ._ipp._t */
0x63, 0x70, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, /* cp.local */
0x00, 0x00, 0x10, 0x80, 0x01, 0x00, 0x00, 0x00, /* ........ */
0x78, 0x00, 0x14, 0x08, 0x70, 0x61, 0x70, 0x65, /* x...pape */ 
0x72, 0x3d, 0x41, 0x34, 0x0a, 0x76, 0x65, 0x72, /* r=A4.ver */
0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x30, 0x31, 0x07, /* sion=01. */
0x75, 0x62, 0x75, 0x6e, 0x74, 0x75, 0x31, 0x05, /* ubuntu1. */
0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x01, /* local... */
0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x04, /* .....x.. */
0xc0, 0xa8, 0x00, 0x1f                          /* ....     */
};

/* Frame (75 bytes) */
static const unsigned char pkt3[75] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb, 0x00, 0x11, /* ..^..... */
0x22, 0x33, 0x44, 0x57, 0x08, 0x00, 0x45, 0x00, /* "3DW..E. */
0x00, 0x3d, 0x00, 0x02, 0x40, 0x00, 0xff, 0x11, /* .=..@... */
0x90, 0x93, 0x0a, 0x00, 0x00, 0x1f, 0xe0, 0x00, /* ........ */
0x00, 0xfb, 0x14, 0xe9, 0x14, 0xe9, 0x00, 0x29, /* .......) */
0x66, 0xba, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* f....... */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x5f, /* ......._ */
0x69, 0x70, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, /* ipp._tcp */
0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, /* .local.. */
0x0c, 0x00, 0x01                                /* ... */
};

static MDNS_QUERY_INFO mdns_query = {NX_NULL, "_ipp._tcp", NX_NULL};
#define resonable_error 10

MDNS_TEST_SEQ mdns_query_rr_timeout[] = {
    {TITLE, "RR timeout", 10, 0},
    
    /* Waiting for probing and announcing.  */
    {WAIT, NX_NULL, 0, 5},

    /* Add query. */
    {MDNS_QUERY, (char*)&mdns_query, 0, 0},
    {MDNS_CHECK_DATA_V4, (char*)&pkt1[0], sizeof(pkt1), 5},

    /* Inject a response. */
    {INJECT, (char*)&pkt2[0], sizeof(pkt2), 0},

    /* Reset timer. */
    {MDNS_TIMER_RESET, NX_NULL, 0, 0},

    /* TTL is 120s. */
    /* Issue a query at 80%, 85%, 90%, 95% of the record lifetime. */
    {WAIT, NX_NULL, 0, 95},
    {DUMP, NX_NULL, 0, 0},

    /* Check data.  */
    {MDNS_CHECK_DATA_V4, (char*)&pkt3[0], sizeof(pkt3), 10},

    /* Check timer in range 96~99s (80%-82%). */
    {MDNS_TIMER_CHECK, NX_NULL, 150 + resonable_error, 9750},
    {DUMP, NX_NULL, 0, 0},

    /* Check data.  */
    {MDNS_CHECK_DATA_V4, (char*)&pkt3[0], sizeof(pkt3), 10},

    /* Check timer in range 102~105 (85%-87%). */
    {MDNS_TIMER_CHECK, NX_NULL, 150 + resonable_error, 10350},
    {DUMP, NX_NULL, 0, 0},

    /* Check data.  */
    {MDNS_CHECK_DATA_V4, (char*)&pkt3[0], sizeof(pkt3), 10},

    /* Check timer in range 108~111 (90%-92%). */
    {MDNS_TIMER_CHECK, NX_NULL, 150 + resonable_error, 10950},
    {DUMP, NX_NULL, 0, 0},

    /* Check data.  */
    {MDNS_CHECK_DATA_V4, (char*)&pkt3[0], sizeof(pkt3), 10},

    /* Check timer in range 114~117 (95%-97%). */
    {MDNS_TIMER_CHECK, NX_NULL, 150 + resonable_error, 11550},

    /* The record should be deleted. */
    {WAIT, NX_NULL, 0, 7},
    {MDNS_CHECK_RR_COUNT_REMOTE, NX_NULL, 0, 0},

    /* Delete the query. */
    {MDNS_QUERY_DELETE, NX_NULL, 0, 0},
    {DUMP, NX_NULL, 0, 0},

    /* Inject a response. */
    {INJECT, (char*)&pkt2[0], sizeof(pkt2), 0},

    /* No cache maintenance is expected. */
    {MDNS_REJECT_ANY_V4, NX_NULL, 0, 120},

    /* The record should be deleted. */
    {WAIT, NX_NULL, 0, 2},
    {MDNS_CHECK_RR_COUNT_REMOTE, NX_NULL, 0, 0},
};

int mdns_query_rr_timeout_size = sizeof(mdns_query_rr_timeout) / sizeof(MDNS_TEST_SEQ);

#endif /* __PRODUCT_NETXDUO__  */