| 1 | // ========== Copyright Header Begin ========================================== |
| 2 | // |
| 3 | // OpenSPARC T2 Processor File: pcg_fa.vr |
| 4 | // Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved |
| 5 | // 4150 Network Circle, Santa Clara, California 95054, U.S.A. |
| 6 | // |
| 7 | // * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 8 | // |
| 9 | // This program is free software; you can redistribute it and/or modify |
| 10 | // it under the terms of the GNU General Public License as published by |
| 11 | // the Free Software Foundation; version 2 of the License. |
| 12 | // |
| 13 | // This program is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | // GNU General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU General Public License |
| 19 | // along with this program; if not, write to the Free Software |
| 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | // |
| 22 | // For the avoidance of doubt, and except that if any non-GPL license |
| 23 | // choice is available it will apply instead, Sun elects to use only |
| 24 | // the General Public License version 2 (GPLv2) at this time for any |
| 25 | // software where a choice of GPL license versions is made |
| 26 | // available with the language indicating that GPLv2 or any later version |
| 27 | // may be used, or where a choice of which version of the GPL is applied is |
| 28 | // otherwise unspecified. |
| 29 | // |
| 30 | // Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 31 | // CA 95054 USA or visit www.sun.com if you need additional information or |
| 32 | // have any questions. |
| 33 | // |
| 34 | // ========== Copyright Header End ============================================ |
| 35 | task gen_buf( integer token, byte_array buf, var integer ptr ) { |
| 36 | |
| 37 | integer len = -1; // L2 length byte pointer |
| 38 | integer n; |
| 39 | integer he; // header end |
| 40 | integer flow_id; |
| 41 | integer ipv4_ptr; |
| 42 | integer ipv6_ptr; |
| 43 | //integer tcp_length; |
| 44 | integer tcp_hdr_start; |
| 45 | |
| 46 | bit [15:0] tcp_length; |
| 47 | bit [31:0] tmp32, mask; |
| 48 | bit [15:0] tmp16 ; |
| 49 | bit [15:0] tmp16_ipck ; |
| 50 | bit [15:0] tmp16_tcpck ; |
| 51 | bit [31:0] isn_tmp; |
| 52 | bit [47:0] da_tmp; |
| 53 | bit [95:0] tcp_psu_hdr; |
| 54 | bit [95:0] udp_psu_hdr; |
| 55 | bit [15:0] ipv4_hdr[10]; |
| 56 | integer tagged = 0; // Tagged frame |
| 57 | bit [32:0] addr; |
| 58 | bit dv; |
| 59 | |
| 60 | ptr=0; |
| 61 | |
| 62 | flow_id = pack_db[token].flow.flow_no; |
| 63 | |
| 64 | |
| 65 | if(INTER_FEDX) { |
| 66 | buf.val[ptr++] = pack_db[token].ifedx_control[07:0]; |
| 67 | buf.val[ptr++] = pack_db[token].ifedx_control[15:8]; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | da_tmp = pack_db[token].dst_node.l2_addr; |
| 72 | /* |
| 73 | |
| 74 | if( check_option( pack_db[token].options, O_USE_MAC_DA) ) { |
| 75 | |
| 76 | case(my_port) { |
| 77 | 0: addr = MAC0_BASE; |
| 78 | 1: addr = MAC1_BASE; |
| 79 | 2: addr = MAC2_BASE; |
| 80 | 3: addr = MAC3_BASE; |
| 81 | } |
| 82 | shadow_class.get_data(addr + MAC_ADDR0, tmp32, mask, dv); |
| 83 | da_tmp[15:00] = tmp32[15:0]; |
| 84 | shadow_class.get_data(addr + MAC_ADDR1, tmp32, mask, dv); |
| 85 | da_tmp[31:16] = tmp32[15:0]; |
| 86 | shadow_class.get_data(addr + MAC_ADDR2, tmp32, mask, dv); |
| 87 | da_tmp[47:32] = tmp32[15:0]; |
| 88 | } // end if |
| 89 | |
| 90 | if( check_option( pack_db[token].options, O_USE_FMAC_DA) ) { |
| 91 | case(my_port) { |
| 92 | 0: da_tmp = shadow_class.mac_shadow_class.fmac0_addr; |
| 93 | 1: da_tmp = shadow_class.mac_shadow_class.fmac1_addr; |
| 94 | 2: da_tmp = shadow_class.mac_shadow_class.fmac2_addr; |
| 95 | 3: da_tmp = shadow_class.mac_shadow_class.fmac3_addr; |
| 96 | } |
| 97 | } |
| 98 | */ |
| 99 | |
| 100 | pack_db[token].dst_node.l2_addr = da_tmp; |
| 101 | |
| 102 | // L2 Header Assembley: Insertion of DA & SA |
| 103 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 104 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } = da_tmp; |
| 105 | |
| 106 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 107 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } = pack_db[token].src_node.l2_addr; |
| 108 | |
| 109 | |
| 110 | // Check to see what kind of L2 pkt it is (802.3 or 802.Q) |
| 111 | if( pack_db[token].frame.frame_type[2] ) { |
| 112 | |
| 113 | // It is a 802.Q Tagged packet |
| 114 | |
| 115 | tagged = 1; |
| 116 | if( pack_db[token].frame.tpid != -1) |
| 117 | '{ buf.val[ptr++], buf.val[ptr++]} = pack_db[token].frame.tpid; |
| 118 | else |
| 119 | '{ buf.val[ptr++], buf.val[ptr++]} = TPID_8021Q; |
| 120 | '{ buf.val[ptr++], buf.val[ptr++]} = pack_db[token].src_node.tci; |
| 121 | } |
| 122 | |
| 123 | |
| 124 | // Check if L3/L4 Header should be appended to packet |
| 125 | if(pack_db[token].frame.frame_type[1] == 1) { |
| 126 | |
| 127 | // L3 Header must be included |
| 128 | |
| 129 | // Check if packet is is an LLC-SNAP L2 packet |
| 130 | if( pack_db[token].frame.frame_type[0] == 1) { |
| 131 | len = ptr; |
| 132 | ptr = ptr+2; |
| 133 | |
| 134 | // Insert LLC value |
| 135 | if( check_option( pack_db[token].options, O_CUSTOM_LS) ) { |
| 136 | tmp32 = cfg_reg[CFG_CUST_LS]; |
| 137 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++]} = tmp32[23:0]; |
| 138 | } else |
| 139 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++]} = LLC_SNAP; |
| 140 | |
| 141 | // SNAP values (last 2B comes from class value) |
| 142 | buf.val[ptr++] = H_UNDEF; |
| 143 | buf.val[ptr++] = H_UNDEF; |
| 144 | buf.val[ptr++] = H_UNDEF; |
| 145 | } else { |
| 146 | |
| 147 | // Regular IP Header |
| 148 | len = - 1; |
| 149 | } |
| 150 | |
| 151 | printf("pcg_fa.vr: frame class %d\n", pack_db[token].frame.frame_class); |
| 152 | |
| 153 | // Convert frame class to IPv6 if necessary. |
| 154 | // (should not be a user defined class) |
| 155 | if( pack_db[token].frame.frame_type[3] == 1 && |
| 156 | pack_db[token].frame.frame_type[4] == 0 && |
| 157 | pack_db[token].frame.frame_class < CL_TCP_OPT ) |
| 158 | pack_db[token].frame.frame_class += DELTA; |
| 159 | else if( pack_db[token].frame.frame_type[4] == 1 && |
| 160 | pack_db[token].frame.tunnel_type[0] == 1 && |
| 161 | pack_db[token].frame.frame_class < CL_TCP_OPT ) |
| 162 | pack_db[token].frame.frame_class += DELTA; |
| 163 | |
| 164 | printf("pcg_fa.vr: NEW frame class %d\n", pack_db[token].frame.frame_class); |
| 165 | // |
| 166 | // Insert L3 Header Info |
| 167 | // |
| 168 | |
| 169 | // Check to see if tunneling option is present |
| 170 | if( pack_db[token].frame.frame_type[4]==1 ) { |
| 171 | |
| 172 | printf("pcg_fa.vr: Tunneling option on, tunnel_type: %h \n", pack_db[token].frame.tunnel_type); |
| 173 | |
| 174 | case( pack_db[token].frame.tunnel_type[1:0]){ |
| 175 | 2'b00: { |
| 176 | // IPv4/IPv4 Header |
| 177 | |
| 178 | // Place packet frame type (L2) & first 12B of L3 Header |
| 179 | for( n=0; n<14; n++) |
| 180 | buf.val[ptr++] = class_mask( pack_db[token].frame.class_funct, |
| 181 | l3_class[CL_IP_TUN_V4_V4].val[n], |
| 182 | l3_mask[pack_db[token].frame.class_mask].val[n] ); |
| 183 | // Insert custom frame type value |
| 184 | if(pack_db[token].frame.type != -1) |
| 185 | '{buf.val[ptr-14], buf.val[ptr-13]} = pack_db[token].frame.type; |
| 186 | |
| 187 | // Insert custom TTL value into IP Header |
| 188 | if(pack_db[token].ttl != -1) buf.val[ptr-4] = pack_db[token].ttl; |
| 189 | |
| 190 | // Insert source/destination IP Addresses |
| 191 | '{ buf.val[ptr++], buf.val[ptr++], |
| 192 | buf.val[ptr++], buf.val[ptr++] } = pack_db[token].src_node.ip_addr; |
| 193 | '{ buf.val[ptr++], buf.val[ptr++], |
| 194 | buf.val[ptr++], buf.val[ptr++] } = pack_db[token].dst_node.ip_addr; |
| 195 | |
| 196 | // 2nd IPv4 Header |
| 197 | |
| 198 | printf("pcg_fa.vr: frame class %d\n", pack_db[token].frame.frame_class ); |
| 199 | // Place packet frame type (L2) & first 12B of L3 Header |
| 200 | for( n=2; n<14; n++) |
| 201 | buf.val[ptr++] = class_mask( pack_db[token].frame.class_funct, |
| 202 | l3_class[pack_db[token].frame.frame_class].val[n], |
| 203 | l3_mask[pack_db[token].frame.class_mask].val[n] ); |
| 204 | // Insert custom frame type value |
| 205 | if(pack_db[token].frame.type != -1) |
| 206 | '{buf.val[ptr-14], buf.val[ptr-13]} = pack_db[token].frame.type; |
| 207 | |
| 208 | // Insert custom TTL value into IP Header |
| 209 | if(pack_db[token].ttl != -1) buf.val[ptr-4] = pack_db[token].ttl; |
| 210 | |
| 211 | // Insert source/destination IP Addresses |
| 212 | '{ buf.val[ptr++], buf.val[ptr++], |
| 213 | buf.val[ptr++], buf.val[ptr++] } = pack_db[token].src_node.ip_addr; |
| 214 | '{ buf.val[ptr++], buf.val[ptr++], |
| 215 | buf.val[ptr++], buf.val[ptr++] } = pack_db[token].dst_node.ip_addr; |
| 216 | } |
| 217 | 2'b01: { |
| 218 | // IPv4/IPv6 Header |
| 219 | |
| 220 | // Place packet frame type (L2) & first 12B of L3 Header |
| 221 | for( n=0; n<14; n++) |
| 222 | buf.val[ptr++] = class_mask( pack_db[token].frame.class_funct, |
| 223 | l3_class[CL_IP_TUN_V4_V6].val[n], |
| 224 | l3_mask[pack_db[token].frame.class_mask].val[n] ); |
| 225 | // Insert custom frame type value |
| 226 | if(pack_db[token].frame.type != -1) |
| 227 | '{buf.val[ptr-14], buf.val[ptr-13]} = pack_db[token].frame.type; |
| 228 | |
| 229 | // Insert custom TTL value into IP Header |
| 230 | if(pack_db[token].ttl != -1) buf.val[ptr-4] = pack_db[token].ttl; |
| 231 | |
| 232 | // Insert source/destination IP Addresses |
| 233 | '{ buf.val[ptr++], buf.val[ptr++], |
| 234 | buf.val[ptr++], buf.val[ptr++] } = pack_db[token].src_node.ip_addr; |
| 235 | '{ buf.val[ptr++], buf.val[ptr++], |
| 236 | buf.val[ptr++], buf.val[ptr++] } = pack_db[token].dst_node.ip_addr; |
| 237 | |
| 238 | // Now Insert IPv6 Header |
| 239 | // Place packet frame type (L2) & first 12B of L3 Header |
| 240 | for( n=2; n<10; n++) |
| 241 | buf.val[ptr++] = class_mask( pack_db[token].frame.class_funct, |
| 242 | l3_class[pack_db[token].frame.frame_class].val[n], |
| 243 | l3_mask[pack_db[token].frame.class_mask].val[n] ); |
| 244 | // Insert custom frame type value |
| 245 | if(pack_db[token].frame.type != -1) |
| 246 | '{buf.val[ptr-10], buf.val[ptr-9]} = pack_db[token].frame.type; |
| 247 | |
| 248 | // Insert source/destination IP Addresses |
| 249 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 250 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 251 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 252 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } = pack_db[token].src_node.ipv6_addr; |
| 253 | |
| 254 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 255 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 256 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 257 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } = pack_db[token].dst_node.ipv6_addr; |
| 258 | } |
| 259 | 2'b10: { |
| 260 | // IPv6/IPv4 Header |
| 261 | |
| 262 | printf("pcg_fa.vr: Tuneling (IPv6/IPv4) doing IPv6\n"); |
| 263 | |
| 264 | // Place packet frame type (L2) & first 12B of L3 Header |
| 265 | for( n=0; n<10; n++) |
| 266 | buf.val[ptr++] = class_mask( pack_db[token].frame.class_funct, |
| 267 | l3_class[CL_IP_TUN_V6_V4].val[n], |
| 268 | l3_mask[pack_db[token].frame.class_mask].val[n] ); |
| 269 | // Insert custom frame type value |
| 270 | if(pack_db[token].frame.type != -1) |
| 271 | '{buf.val[ptr-10], buf.val[ptr-9]} = pack_db[token].frame.type; |
| 272 | |
| 273 | // Insert source/destination IP Addresses |
| 274 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 275 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 276 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 277 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } = pack_db[token].src_node.ipv6_addr; |
| 278 | |
| 279 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 280 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 281 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 282 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } = pack_db[token].dst_node.ipv6_addr; |
| 283 | |
| 284 | printf("pcg_fa.vr: Tuneling (IPv6/IPv4) doing IPv4\n"); |
| 285 | |
| 286 | // Now Insert IPv4 Header |
| 287 | |
| 288 | // Place packet frame type (L2) & first 12B of L3 Header |
| 289 | for( n=2; n<14; n++) |
| 290 | buf.val[ptr++] = class_mask( pack_db[token].frame.class_funct, |
| 291 | l3_class[pack_db[token].frame.frame_class].val[n], |
| 292 | l3_mask[pack_db[token].frame.class_mask].val[n] ); |
| 293 | // Insert custom frame type value |
| 294 | if(pack_db[token].frame.type != -1) |
| 295 | '{buf.val[ptr-14], buf.val[ptr-13]} = pack_db[token].frame.type; |
| 296 | |
| 297 | // Insert custom TTL value into IP Header |
| 298 | if(pack_db[token].ttl != -1) buf.val[ptr-4] = pack_db[token].ttl; |
| 299 | |
| 300 | // Insert source/destination IP Addresses |
| 301 | '{ buf.val[ptr++], buf.val[ptr++], |
| 302 | buf.val[ptr++], buf.val[ptr++] } = pack_db[token].src_node.ip_addr; |
| 303 | '{ buf.val[ptr++], buf.val[ptr++], |
| 304 | buf.val[ptr++], buf.val[ptr++] } = pack_db[token].dst_node.ip_addr; |
| 305 | } |
| 306 | 2'b11: { |
| 307 | // IPv6/IPv6 Header |
| 308 | |
| 309 | // Place packet frame type (L2) & first 12B of L3 Header |
| 310 | for( n=0; n<10; n++) |
| 311 | buf.val[ptr++] = class_mask( pack_db[token].frame.class_funct, |
| 312 | l3_class[CL_IP_TUN_V6_V6].val[n], |
| 313 | l3_mask[pack_db[token].frame.class_mask].val[n] ); |
| 314 | // Insert custom frame type value |
| 315 | if(pack_db[token].frame.type != -1) |
| 316 | '{buf.val[ptr-10], buf.val[ptr-9]} = pack_db[token].frame.type; |
| 317 | |
| 318 | // Insert source/destination IP Addresses |
| 319 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 320 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 321 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 322 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } = pack_db[token].src_node.ipv6_addr; |
| 323 | |
| 324 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 325 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 326 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 327 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } = pack_db[token].dst_node.ipv6_addr; |
| 328 | |
| 329 | // Now Insert IPv6 Header |
| 330 | |
| 331 | // Place packet frame type (L2) & first 12B of L3 Header |
| 332 | for( n=2; n<10; n++) |
| 333 | buf.val[ptr++] = class_mask( pack_db[token].frame.class_funct, |
| 334 | l3_class[pack_db[token].frame.frame_class].val[n], |
| 335 | l3_mask[pack_db[token].frame.class_mask].val[n] ); |
| 336 | // Insert custom frame type value |
| 337 | if(pack_db[token].frame.type != -1) |
| 338 | '{buf.val[ptr-10], buf.val[ptr-9]} = pack_db[token].frame.type; |
| 339 | |
| 340 | // Insert source/destination IP Addresses |
| 341 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 342 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 343 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 344 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } = pack_db[token].src_node.ipv6_addr; |
| 345 | |
| 346 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 347 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 348 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 349 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } = pack_db[token].dst_node.ipv6_addr; |
| 350 | } |
| 351 | } // end case |
| 352 | } |
| 353 | // check to see if regular L3 Header should be IPv4 or IPv6 |
| 354 | else if( pack_db[token].frame.frame_type[3] == 0 ) { |
| 355 | |
| 356 | printf("pcg_fa.vr: Building IPv4 packet \n"); |
| 357 | |
| 358 | // This is an IPv4 Packet |
| 359 | |
| 360 | //Place packet frame type (L2) & first 12B of L3 Header//NVN-- 12 frm 14 |
| 361 | for( n=0; n<2; n++) |
| 362 | buf.val[ptr++] = class_mask( pack_db[token].frame.class_funct, |
| 363 | l3_class[pack_db[token].frame.frame_class].val[n], |
| 364 | l3_mask[pack_db[token].frame.class_mask].val[n] ); |
| 365 | |
| 366 | for( n=2; n<12; n++) |
| 367 | buf.val[ptr++] = class_mask( pack_db[token].frame.class_funct, |
| 368 | l3_class[pack_db[token].frame.frame_class].val[n], |
| 369 | l3_mask[pack_db[token].frame.class_mask].val[n] ); |
| 370 | |
| 371 | // Insert custom frame type value |
| 372 | if(pack_db[token].frame.type != -1) |
| 373 | '{buf.val[ptr-14], buf.val[ptr-13]} = pack_db[token].frame.type; |
| 374 | |
| 375 | // Insert custom TTL value into IP Header |
| 376 | if(pack_db[token].ttl != -1) buf.val[ptr-2] = pack_db[token].ttl;//NVN 2 frm 4 |
| 377 | |
| 378 | |
| 379 | |
| 380 | // Initaialize the IP checksum to "0" |
| 381 | '{buf.val[ptr++],buf.val[ptr++]} = 16'h0000; |
| 382 | |
| 383 | |
| 384 | // Insert source/destination IP Addresses |
| 385 | '{ buf.val[ptr++], buf.val[ptr++], |
| 386 | buf.val[ptr++], buf.val[ptr++] } = pack_db[token].src_node.ip_addr; |
| 387 | '{ buf.val[ptr++], buf.val[ptr++], |
| 388 | buf.val[ptr++], buf.val[ptr++] } = pack_db[token].dst_node.ip_addr; |
| 389 | |
| 390 | printf("The val of ptr is %d /n",ptr); |
| 391 | |
| 392 | tmp16_ipck = ipv4_cksum(buf,ptr); |
| 393 | |
| 394 | // '{buf.val[ptr-10],buf.val[ptr-9]} = 16'h1415; |
| 395 | '{buf.val[ptr-10],buf.val[ptr-9]} = tmp16_ipck; |
| 396 | |
| 397 | } // end if IPv4 Header |
| 398 | else if ( pack_db[token].frame.frame_type[3] == 1 ) { |
| 399 | |
| 400 | // This is an IPv6 Packet |
| 401 | printf("pcg_fa.vr: Bulding IPv6 Packet \n"); |
| 402 | |
| 403 | // Place packet frame type (L2) & first 12B of L3 Header//NVN |
| 404 | for( n=0; n<2; n++) |
| 405 | buf.val[ptr++] = class_mask( pack_db[token].frame.class_funct, |
| 406 | l3_class[pack_db[token].frame.frame_class].val[n], |
| 407 | l3_mask[pack_db[token].frame.class_mask].val[n] ); |
| 408 | for( n=2; n<10; n++) |
| 409 | buf.val[ptr++] = class_mask( pack_db[token].frame.class_funct, |
| 410 | l3_class[pack_db[token].frame.frame_class].val[n], |
| 411 | l3_mask[pack_db[token].frame.class_mask].val[n] ); |
| 412 | // Insert custom frame type value |
| 413 | if(pack_db[token].frame.type != -1) |
| 414 | '{buf.val[ptr-10], buf.val[ptr-9]} = pack_db[token].frame.type; |
| 415 | |
| 416 | // Insert custom TTL value into Hop Limit of IPV6 Header |
| 417 | if(pack_db[token].ttl != -1) buf.val[ptr-1] = pack_db[token].ttl;//NVN |
| 418 | |
| 419 | // Insert source/destination IP Addresses |
| 420 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 421 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 422 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 423 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } = pack_db[token].src_node.ipv6_addr; |
| 424 | |
| 425 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 426 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 427 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], |
| 428 | buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } = pack_db[token].dst_node.ipv6_addr; |
| 429 | |
| 430 | |
| 431 | } // end if IPv6 Header |
| 432 | |
| 433 | printf("pcg_fa.vr: Frame_class: %d\n" , pack_db[token].frame.frame_class ); |
| 434 | |
| 435 | |
| 436 | // |
| 437 | // Insert L4 header Info |
| 438 | // |
| 439 | |
| 440 | if( pack_db[token].frame.frame_class == CL_UDP | |
| 441 | pack_db[token].frame.frame_class == CL_UDP_OPT | |
| 442 | pack_db[token].frame.frame_class == CL_UDP_FRAG | |
| 443 | pack_db[token].frame.frame_class == CL_UDP_IP_V6 | |
| 444 | pack_db[token].frame.frame_class == CL_UDP_OPT_IP_V6 | |
| 445 | pack_db[token].frame.frame_class == CL_UDP_FRAG_IP_V6 ) { |
| 446 | |
| 447 | printf("pcg_fa.vr: Adding UDP Header \n"); |
| 448 | |
| 449 | udp_psu_hdr = {pack_db[token].src_node.ip_addr, |
| 450 | pack_db[token].dst_node.ip_addr, |
| 451 | 8'h00,8'h17,tcp_length}; |
| 452 | |
| 453 | // Insert source/destination port numbers |
| 454 | '{ buf.val[ptr++], buf.val[ptr++] } = pack_db[token].tup.src_tcp_udp_port; |
| 455 | '{ buf.val[ptr++], buf.val[ptr++] } = pack_db[token].tup.dst_tcp_udp_port; |
| 456 | |
| 457 | tmp32 = cfg_reg[CFG_UDP_LEN]; |
| 458 | '{ buf.val[ptr++], buf.val[ptr++] } = tmp32[15:0]; |
| 459 | tmp32 = cfg_reg[CFG_UDP_CSM]; |
| 460 | '{ buf.val[ptr++], buf.val[ptr++] } = tmp32[15:0]; |
| 461 | |
| 462 | } // end if UPD pkt |
| 463 | |
| 464 | else if ( pack_db[token].frame.frame_class == CL_TCP | |
| 465 | pack_db[token].frame.frame_class == CL_TCP_OPT | |
| 466 | pack_db[token].frame.frame_class == CL_TCP_FRAG | |
| 467 | pack_db[token].frame.frame_class == CL_TCP_IP_V6 | |
| 468 | pack_db[token].frame.frame_class == CL_TCP_OPT_IP_V6 | |
| 469 | pack_db[token].frame.frame_class == CL_TCP_FRAG_IP_V6 ) { |
| 470 | |
| 471 | printf("pcg_fa.vr: Adding TCP Header \n"); |
| 472 | |
| 473 | tcp_psu_hdr = {pack_db[token].src_node.ip_addr, |
| 474 | pack_db[token].dst_node.ip_addr, |
| 475 | 8'h00,8'h06,tcp_length}; |
| 476 | |
| 477 | //tcp_hdr_start = ptr + 1; |
| 478 | tcp_hdr_start = ptr ; |
| 479 | |
| 480 | // Insert source/destination port numbers |
| 481 | '{ buf.val[ptr++], buf.val[ptr++] } = pack_db[token].tup.src_tcp_udp_port; |
| 482 | '{ buf.val[ptr++], buf.val[ptr++] } = pack_db[token].tup.dst_tcp_udp_port; |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | if( pack_db[token].fl_state.tcp_flags == 2'h02 ) { |
| 488 | |
| 489 | '{ buf.val[ptr++], buf.val[ptr++], |
| 490 | buf.val[ptr++], buf.val[ptr++] } = pack_db[token].rx_param.rcv_isn; |
| 491 | |
| 492 | } |
| 493 | |
| 494 | else { |
| 495 | |
| 496 | '{ buf.val[ptr++], buf.val[ptr++], |
| 497 | buf.val[ptr++], buf.val[ptr++] } = flow_db[flow_id].tx_param.last_seqno; |
| 498 | |
| 499 | flow_db[flow_id].rx_param.rcv_isn = flow_db[flow_id].tx_param.last_seqno; |
| 500 | |
| 501 | flow_db[flow_id].data_length = pack_db[token].data_length; |
| 502 | |
| 503 | } |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | flow_db[flow_id].tx_param.last_seqno = {(flow_db[flow_id].rx_param.rcv_isn) + (flow_db[flow_id].data_length)}; |
| 509 | |
| 510 | |
| 511 | |
| 512 | '{ buf.val[ptr++], buf.val[ptr++], |
| 513 | buf.val[ptr++], buf.val[ptr++] } = cfg_reg[CFG_TCP_ACK]; |
| 514 | |
| 515 | tmp32[15:0] = {cfg_reg[CFG_TCP_LEN], 6'b000000, pack_db[token].fl_state.tcp_flags} ; |
| 516 | '{ buf.val[ptr++], buf.val[ptr++] } = tmp32[15:0]; |
| 517 | |
| 518 | tmp32 = cfg_reg[CFG_TCP_WIN]; |
| 519 | '{ buf.val[ptr++], buf.val[ptr++] } = tmp32[15:0]; |
| 520 | |
| 521 | |
| 522 | //tmp32 = cfg_reg[CFG_TCP_CSM]; |
| 523 | '{ buf.val[ptr++], buf.val[ptr++] } = 16'h00; |
| 524 | |
| 525 | tmp32 = cfg_reg[CFG_TCP_URG]; |
| 526 | '{ buf.val[ptr++], buf.val[ptr++] } = tmp32[15:0]; |
| 527 | |
| 528 | } // end if TCP pkt |
| 529 | |
| 530 | } // end if( pack_db[token].frame.frame_type[1] == 1) |
| 531 | else { |
| 532 | // No L3/L4 Header |
| 533 | printf("pcg_fa.vr: No L3 header selected\n"); |
| 534 | len = ptr; |
| 535 | ptr = ptr+2; |
| 536 | } |
| 537 | |
| 538 | he = ptr-1; |
| 539 | |
| 540 | |
| 541 | tcp_length = pack_db[token].data_length -he -4; |
| 542 | |
| 543 | |
| 544 | if(pack_db[token].frame.data_type != DAT_FC_PAUSE) |
| 545 | '{buf.val[ptr++], buf.val[ptr++]} = token; |
| 546 | |
| 547 | data_gen( pack_db[token].frame.data_type, |
| 548 | pack_db[token].frame.data_seed, |
| 549 | pack_db[token].data_length, |
| 550 | buf, ptr, pack_db[token].options, this, tagged, INTER_FEDX); |
| 551 | |
| 552 | // Insert Len value for L2 Header |
| 553 | if( len > 0 ) { |
| 554 | if( check_option( pack_db[token].options, O_FRM_LEN_ERR1) ) |
| 555 | '{buf.val[len], buf.val[len+1] } = cfg_reg[CFG_FRM_LEN]; |
| 556 | else { |
| 557 | if(pack_db[token].frame.type == -1) { |
| 558 | '{buf.val[len], buf.val[len+1] } = ptr - (he+1); |
| 559 | } else |
| 560 | '{buf.val[len], buf.val[len+1] } = pack_db[token].frame.type; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | //Add TCP Checksum |
| 565 | |
| 566 | printf("TCP hdr start is %d/n",tcp_hdr_start); |
| 567 | |
| 568 | tmp16_tcpck = tcp_chksum(tcp_psu_hdr,buf,tcp_hdr_start,ptr); |
| 569 | '{buf.val[he-3],buf.val[he-2]} = tmp16_tcpck; |
| 570 | |
| 571 | if(INTER_FEDX) pack_db_add_header(token,buf,2,he); // Start at byte 2 (skip control word) |
| 572 | else pack_db_add_header(token,buf,0,he); // Start at byte 0 |
| 573 | |
| 574 | // Insert CRC |
| 575 | if(INTER_FEDX) |
| 576 | tmp32 = crc_gen(buf, 2, ptr); |
| 577 | else |
| 578 | tmp32 = crc_gen(buf, 0, ptr); |
| 579 | |
| 580 | if( check_option( pack_db[token].options, O_CRC_ERR) ) tmp32 = tmp32 ^ cfg_reg[CFG_CRC_MASK]; |
| 581 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } = tmp32; |
| 582 | pack_db[token].pack_crc = tmp32; |
| 583 | |
| 584 | if(INTER_FEDX) { |
| 585 | tmp32 = crc_gen(buf, 0, ptr); |
| 586 | if( check_option( pack_db[token].options, O_IF_CRC_ERR) ) tmp32 = tmp32 ^ cfg_reg[CFG_CRC_MASK]; |
| 587 | '{ buf.val[ptr++], buf.val[ptr++], buf.val[ptr++], buf.val[ptr++] } = tmp32; |
| 588 | pack_db[token].ifedx_crc = tmp32; |
| 589 | } |
| 590 | |
| 591 | pack_db[token].frame_len = ptr; |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | } // end task |
| 598 | |
| 599 | |
| 600 | |
| 601 | function bit [15:0] ipv4_cksum( byte_array m, integer len){ |
| 602 | |
| 603 | integer i,j; |
| 604 | bit [15:0] tmp[20]; |
| 605 | bit [15:0] tmp_inv[20]; |
| 606 | bit [15:0] cksum; |
| 607 | |
| 608 | |
| 609 | cksum = 0; |
| 610 | |
| 611 | for ( j=1; j<20; j=j+2) |
| 612 | tmp[j] = {m.val[len-j], m.val[len-(j+1)]}; |
| 613 | |
| 614 | |
| 615 | |
| 616 | cksum = { tmp[19] + tmp[17] + tmp[15] + tmp[13] + tmp[11] + tmp[9] + tmp[7] + tmp[5] + tmp[3] + tmp[1]}; |
| 617 | |
| 618 | cksum = (cksum & 16'hFFFF) + ( cksum >> 16); |
| 619 | |
| 620 | if (cksum > 16'hFFFF) |
| 621 | cksum -= 16'hFFFF; |
| 622 | |
| 623 | ipv4_cksum = ~cksum; |
| 624 | |
| 625 | } |
| 626 | |
| 627 | function bit [15:0] tcp_chksum( bit[95:0]psu_hdr,byte_array d, integer start, integer len){ |
| 628 | |
| 629 | integer i,j,k; |
| 630 | bit [15:0] tmp[]; |
| 631 | bit [15:0] tcp_tmp[6]; |
| 632 | bit [15:0] sum_hdr; |
| 633 | |
| 634 | for ( j=0; j<5; j++) |
| 635 | tcp_tmp[j] = tcp_tmp[j]; |
| 636 | printf("Starting TCP Chksum function \n"); |
| 637 | |
| 638 | for (i=start;i<len;i=i+2) |
| 639 | tmp[i] = {d.val[i],d.val[i+1]}; |
| 640 | |
| 641 | tcp_tmp[0] = psu_hdr[95:80]; |
| 642 | tcp_tmp[1] = psu_hdr[79:64]; |
| 643 | tcp_tmp[2] = psu_hdr[63:48]; |
| 644 | tcp_tmp[3] = psu_hdr[47:32]; |
| 645 | tcp_tmp[4] = psu_hdr[31:16]; |
| 646 | tcp_tmp[5] = psu_hdr[15:0]; |
| 647 | |
| 648 | //for ( k=0; k<5; k++) |
| 649 | // sum_hdr += tcp_tmp[k]; |
| 650 | |
| 651 | sum_hdr = tcp_tmp[0] + tcp_tmp[1] + tcp_tmp[2] + tcp_tmp[3] + tcp_tmp[4] ; |
| 652 | |
| 653 | tcp_chksum = sum_hdr; |
| 654 | |
| 655 | } |
| 656 | |
| 657 | |