/** * @author Ian Johnson * @version 1.0 */ //return reversed 1 means good, 0 means failed #include #include #include #include #include #include #include #include "xfs_types.h" #include "xparameters.h" #include "Beb.h" using namespace std; BebInfo::BebInfo(unsigned int beb_num){beb_number=beb_num;serial_address=0;src_mac_1GbE="";src_mac_10GbE="";src_ip_1GbE="";src_ip_10GbE=""; src_port_1GbE=src_port_10GbE=0;} bool BebInfo::SetHeaderInfo(bool ten_gig, string src_mac, string src_ip, unsigned int src_port){ if(ten_gig){ src_mac_10GbE = src_mac; src_ip_10GbE = src_ip; src_port_10GbE = src_port;} else { src_mac_1GbE = src_mac; src_ip_1GbE = src_ip; src_port_1GbE = src_port;} return 1; } bool BebInfo::SetSerialAddress(unsigned int a){ //address pre shifted if(a>0xff) return 0; serial_address = 0x04000000 | ((a&0xff)<<16); return 1; } void BebInfo::Print(){ cout<<"\t"<Print(); cout<InitNewMemory(XPAR_PLB_LL_NEW_MEMORY, arg1)) printf("New Memory FAIL\n"); else printf("New Memory OK\n"); } Beb::~Beb(){ delete ll; delete [] send_data_raw; delete [] recv_data_raw; } void Beb::ClearBebInfos(){ for(unsigned int i=0;iSetSerialAddress(0xff)) beb_infos.push_back(b0); //all bebs for reset and possibly get request data? if(!ReadSetUpFromFile("/home/root/executables/setup_beb.txt")) return 0; /* //loop through file to fill vector. BebInfo* b = new BebInfo(26); b->SetSerialAddress(0); //0xc4000000 b->SetHeaderInfo(0,"00:50:c2:46:d9:34","129.129.205.78",42000 + 26); // 1 GbE, ip address can be acquire from the network "arp" b->SetHeaderInfo(1,"00:50:c2:46:d9:35","10.0.26.1",52000 + 26); //10 GbE, everything calculable/setable beb_infos.push_back(b); */ return CheckSourceStuffBebInfo(); } bool Beb::SetBebSrcHeaderInfos(unsigned int beb_number, bool ten_gig, string src_mac, string src_ip,unsigned int src_port){ //so that the values can be reset externally for now.... unsigned int i = GetBebInfoIndex(beb_number); if(!i) return 0; //i must be greater than 0, zero is the global send beb_infos[i]->SetHeaderInfo(ten_gig,src_mac,src_ip,src_port); cout<<"Printing Beb info number ("<Print(); cout<>cmd_st; if(!strcmp("add_beb",cmd_st)){ if(!(iss>>value_i[0]>>value_i[1]>>str_mac1>>str_ip1>>str_mac10>>str_ip10)){ cout<<"Error adding beb from "<SetSerialAddress(value_i[1]); b->SetHeaderInfo(0,str_mac1,str_ip1,42000+value_i[0]); b->SetHeaderInfo(1,str_mac10,str_ip10,52000+value_i[0]); beb_infos.push_back(b); } } infile.close(); return 1; } bool Beb::CheckSourceStuffBebInfo(){ for(unsigned int i=1;iGetBebNumber(),0,"00:00:00:00:00:00","10.0.0.1",20000)||!SetHeaderData(beb_infos[i]->GetBebNumber(),1,"00:00:00:00:00:00","10.0.0.1",20000)){ cout<<"Error in BebInfo for module number "<GetBebNumber()<<"."<Print(); return 0; } } return 1; } unsigned int Beb::GetBebInfoIndex(unsigned int beb_numb){ if(!beb_numb) return 0; for(unsigned int i=1;iGetBebNumber()) return i; return 0; } bool Beb::WriteTo(unsigned int index){ if(index>=beb_infos.size()){ cout<<"WriteTo index error."<GetSerialAddress(); if(ll->Write(4,send_data_raw)!=4) return 0; send_data_raw[0] = 0xc0000000; if((send_ndata+1)*4!=ll->Write((send_ndata+1)*4,send_data_raw)) return 0; return 1; } void Beb::SwapDataFun(bool little_endian, unsigned int n, unsigned int *d){ if(little_endian) for(unsigned int i=0;i>8) | ((d[i]&0xff000000)>>24)); //little_endian else for(unsigned int i=0;i>16)); } bool Beb::SetByteOrder(){ send_data_raw[0] = 0x8fff0000; if(ll->Write(4,send_data_raw)!=4) return 0; while((ll->Read(recv_buffer_size*4,recv_data_raw)/4)>0) cout<<"\t) Cleanning buffer ..."<GetSrcMAC(ten_gig),beb_infos[i]->GetSrcIP(ten_gig),beb_infos[i]->GetSrcPort(ten_gig),dst_mac,dst_ip,dst_port); } bool Beb::SetHeaderData(string src_mac, string src_ip, unsigned int src_port, string dst_mac, string dst_ip, unsigned int dst_port){ /* example header*/ //static unsigned int* word_ptr = new unsigned int [16]; static udp_header_type udp_header = { {0x00, 0x50, 0xc5, 0xb2, 0xcb, 0x46}, // DST MAC {0x00, 0x50, 0xc2, 0x46, 0xd9, 0x02}, // SRC MAC {0x08, 0x00}, {0x45}, {0x00}, {0x00, 0x00}, {0x00, 0x00}, {0x40}, {0x00}, {0xff}, {0x11}, {0x00, 0x00}, {129, 205, 205, 128}, // Src IP {129, 205, 205, 122}, // Dst IP {0x0f, 0xa1}, {0x13, 0x89}, {0x00, 0x00}, //{0x00, 0x11}, {0x00, 0x00} }; if(!SetMAC(src_mac,&(udp_header.src_mac[0]))) return 0; if(!SetIP(src_ip,&(udp_header.src_ip[0]))) return 0; if(!SetPortNumber(src_port,&(udp_header.src_port[0]))) return 0; if(!SetMAC(dst_mac,&(udp_header.dst_mac[0]))) return 0; if(!SetIP(dst_ip,&(udp_header.dst_ip[0]))) return 0; if(!SetPortNumber(dst_port,&(udp_header.dst_port[0]))) return 0; AdjustIPChecksum(&udp_header); unsigned int* base_ptr = (unsigned int *) &udp_header; unsigned int num_words = ( sizeof(udp_header_type) + 3 ) / 4; // for(unsigned int i=0; i "<3))||(i==3&&(ip.length()<1||ip.length()>3))){ cout<<"Error: in ip address -> "<> 8) & 0xff ; dst_ptr[1] = port_number & 0xff; return 1; } void Beb::AdjustIPChecksum(udp_header_type *ip){ unsigned char *cptr = (unsigned char *) ip->ver_headerlen; ip->ip_header_checksum[0] = 0; ip->ip_header_checksum[1] = 0; ip->total_length[0] = 0; ip->total_length[1] = 28; // IP + UDP Header Length // calc ip checksum unsigned int ip_checksum = 0; for(unsigned int i=0; i<10; i++){ ip_checksum += ( (cptr[2*i] << 8) + (cptr[2*i + 1]) ); if (ip_checksum & 0x00010000) ip_checksum = (ip_checksum + 1) & 0x0000ffff; } ip->ip_header_checksum[0] = (ip_checksum >> 8) & 0xff ; ip->ip_header_checksum[1] = ip_checksum & 0xff ; } bool Beb::SendMultiReadRequest(unsigned int beb_number, unsigned int left_right, bool ten_gig, unsigned int dst_number, unsigned int npackets, unsigned int packet_size, bool stop_read_when_fifo_empty){ unsigned int i = GetBebInfoIndex(beb_number); //zero is the global send send_ndata = 3; if(left_right == 1) send_data[0] = 0x00040000; else if(left_right == 2) send_data[0] = 0x00080000; else if(left_right == 3) send_data[0] = 0x000c0000; else return 0; //packet_size/=2; if(dst_number>0x3f) return 0; if(packet_size>0x3ff) return 0; if(npackets==0||npackets>0x100) return 0; npackets--; send_data[1] = 0x62000000 | (!stop_read_when_fifo_empty) << 27 | (ten_gig==1) << 24 | packet_size << 14 | dst_number << 8 | npackets; send_data[2] = 0; SwapDataFun(0,2,&(send_data[1])); if(!WriteTo(i)) return 0; return 1; } bool Beb::SetUpTransferParameters(short the_bit_mode){ if(the_bit_mode!=4&&the_bit_mode!=8&&the_bit_mode!=16&&the_bit_mode!=32) return 0; bit_mode = the_bit_mode; //nimages = the_number_of_images; // on_dst = 0; return 1; } bool Beb::RequestNImages(unsigned int beb_number, unsigned int left_right, bool ten_gig, unsigned int dst_number, unsigned int nimages, bool test_just_send_out_packets_no_wait){ if(dst_number>64) return 0; unsigned int header_size = 4; //4*64 bits unsigned int packet_size = ten_gig ? 0x200 : 0x80; // 4k or 1k packets unsigned int npackets = ten_gig ? bit_mode*4 : bit_mode*16; bool in_two_requests = (!ten_gig&&bit_mode==32); if(in_two_requests) npackets/=2; //cout<<"here: "<