source: test/test-mpls.c @ e78e408

develop
Last change on this file since e78e408 was e78e408, checked in by Jacob van Walraven <jacobvw@…>, 21 months ago

Add some tests for trace_get_outermost_vlan, trace_get_outermost_mpls and trace_get_layer2_headers

  • Property mode set to 100644
File size: 1.5 KB
Line 
1#include "libtrace.h"
2#include <stdio.h>
3#include <stdlib.h>
4
5void iferr(libtrace_t *trace)
6{
7        libtrace_err_t err = trace_get_err(trace);
8        if (err.err_num==0)
9                return;
10        printf("Error: %s\n",err.problem);
11        exit(1);
12}
13
14
15int main(int argc, char *argv[]) {
16
17        libtrace_t *trace = NULL;
18        libtrace_packet_t *packet = NULL;
19        int i = 0;
20        uint16_t mplslabel;
21        uint8_t *mplsptr;
22        uint32_t remaining;
23        int error = 0;
24
25        packet = trace_create_packet();
26
27        trace = trace_create("pcapfile:traces/mpls.pcap");
28        iferr(trace);
29
30        trace_start(trace);
31        iferr(trace);
32
33        /* read a packet */
34        trace_read_packet(trace, packet);
35        /* first packet in this trace should have a vlan tag of 32 */
36        mplslabel = trace_get_outermost_mpls(packet, &mplsptr, &remaining);
37        if (mplslabel != 18) {
38                printf("Failed to find correct outermost vlan tag\n");
39                error = 1;
40        }
41
42        /* Second packet should not contain a MPLS label */
43        trace_read_packet(trace, packet);
44        mplslabel = trace_get_outermost_mpls(packet, &mplsptr, &remaining);
45        if (mplslabel != MPLS_NOT_FOUND) {
46                printf("Found MPLS label with none present\n");
47                error = 1;
48        }
49
50        /* read a packet */
51        trace_read_packet(trace, packet);
52        mplslabel = trace_get_outermost_mpls(packet, &mplsptr, &remaining);
53        if (mplslabel != 18) {
54                printf("Failed to find correct outermost vlan tag\n");
55                error = 1;
56        }
57
58        if (error == 0) {
59                printf("success\n");
60        } else {
61                iferr(trace);
62        }
63
64        trace_destroy(trace);
65        trace_destroy_packet(packet);
66
67        return error;
68}
Note: See TracBrowser for help on using the repository browser.