Modify OpenFlow commands related to ports to be more expressive.
[sliver-openvswitch.git] / datapath / crc_t.c
1 /*
2  * Distributed under the terms of the GNU GPL version 2.
3  * Copyright (c) 2007, 2008 The Board of Trustees of The Leland 
4  * Stanford Junior University
5  */
6
7 #include <linux/string.h>
8 #include <linux/kernel.h>
9
10 #include "crc32.h"
11 #include "unit.h"
12
13
14 static void
15 print_error(unsigned int poly, char *data,
16                         unsigned int expected, unsigned int calculated)
17 {
18         unit_fail("crc error: poly=%x data=%s expected=%x calculated=%x\n",
19                                 poly, data, expected, calculated);
20 }
21
22 void
23 run_crc_t(void)
24 {
25         struct crc32 crc;
26         unsigned int val, i, j;
27
28         char *data[3] = { "h3rei$@neX@mp13da7@sTr117G0fCH@r$",
29                                 "1324lkqasdf0-[LKJD0;asd,.cv;/asd0:\"'~`co29",
30                                 "6" };
31
32         unsigned int polys[2] = { 0x04C11DB7,
33                                 0x1EDC6F41 };
34
35         unsigned int crc_values[2][3] = { 
36                                 { 0xDE1040C3, 0x65343A0B, 0xCEB42022 },
37                                 { 0x6C149FAE, 0x470A6B73, 0x4D3AA134 } };
38         for (i = 0; i < 2; i++) {
39                 crc32_init(&crc, polys[i]);
40                 for (j = 0; j < 3; j++) {
41                         val = crc32_calculate(&crc, data[j], strlen(data[j]));
42                         if (val != crc_values[i][j]) {
43                                 print_error(polys[i], data[j], crc_values[i][j], val);
44                         }
45                 }
46         }
47 }