├── img ├── 1.PNG ├── 2.PNG ├── 3.PNG ├── 4.PNG ├── 5.PNG ├── 6.PNG ├── 7.PNG └── file.PNG ├── Assignment#1 ├── 1.PNG ├── 2.PNG ├── 3.PNG ├── 4.PNG ├── 5.PNG └── 2015112167CDMA.cpp ├── Assignment#2 ├── generator.cpp ├── alter.cpp └── verifier.cpp └── README.md /img/1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easthobb/Data-Communication-2019-2/main/img/1.PNG -------------------------------------------------------------------------------- /img/2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easthobb/Data-Communication-2019-2/main/img/2.PNG -------------------------------------------------------------------------------- /img/3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easthobb/Data-Communication-2019-2/main/img/3.PNG -------------------------------------------------------------------------------- /img/4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easthobb/Data-Communication-2019-2/main/img/4.PNG -------------------------------------------------------------------------------- /img/5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easthobb/Data-Communication-2019-2/main/img/5.PNG -------------------------------------------------------------------------------- /img/6.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easthobb/Data-Communication-2019-2/main/img/6.PNG -------------------------------------------------------------------------------- /img/7.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easthobb/Data-Communication-2019-2/main/img/7.PNG -------------------------------------------------------------------------------- /img/file.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easthobb/Data-Communication-2019-2/main/img/file.PNG -------------------------------------------------------------------------------- /Assignment#1/1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easthobb/Data-Communication-2019-2/main/Assignment#1/1.PNG -------------------------------------------------------------------------------- /Assignment#1/2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easthobb/Data-Communication-2019-2/main/Assignment#1/2.PNG -------------------------------------------------------------------------------- /Assignment#1/3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easthobb/Data-Communication-2019-2/main/Assignment#1/3.PNG -------------------------------------------------------------------------------- /Assignment#1/4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easthobb/Data-Communication-2019-2/main/Assignment#1/4.PNG -------------------------------------------------------------------------------- /Assignment#1/5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easthobb/Data-Communication-2019-2/main/Assignment#1/5.PNG -------------------------------------------------------------------------------- /Assignment#2/generator.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easthobb/Data-Communication-2019-2/main/Assignment#2/generator.cpp -------------------------------------------------------------------------------- /Assignment#2/alter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | using namespace std; 6 | 7 | /* generator의 표준 출력의 비트를 임의로 변경시키기 위해서 사용하는 함수*/ 8 | int main(int argc, char *argv[]){ // 사용자로부터 실행 인자로 정수를 입력 받음 9 | 10 | int changeIndex = atoi(argv[1]); // argv[1]로 전해진 char* 형태의 변수를 atoi()함수를 통해 정수로 변환합니다. 11 | 12 | string FRAME; 13 | string GENERATOR; 14 | 15 | /*표준입력*/ 16 | getline(cin,FRAME); 17 | getline(cin,GENERATOR); 18 | 19 | /*사용자가 FRAME의 size를 over 했을 경우 alter 하지 않고 종료*/ 20 | if(changeIndex>FRAME.length()) 21 | return 0; 22 | else{ 23 | /*사용자가 입력한 정수에 해당하는 index의 값을 반전시킵니다. 0->1 , 1->0*/ 24 | if(FRAME[changeIndex]=='1') 25 | FRAME[changeIndex]='0'; 26 | else 27 | FRAME[changeIndex]='1'; 28 | } 29 | 30 | /*표준출력*/ 31 | cout< 2 | #include 3 | #include 4 | 5 | 6 | using namespace std; 7 | /* MOD-2 연산을 수행하는 함수, 첫번째 인자로 받는 tempFrame을 두 번째 인자로 받는 GENERATOR가 mod-2 연산을 수행*/ 8 | string mod2Op(string tempFrame, string GENERATOR) { 9 | 10 | 11 | for (int i = 0; tempFrame.length() >= GENERATOR.length(); i++)//tempFrame 의 길이가 generator보다 짧아질 때까지 연산 수행 12 | { 13 | if (tempFrame[0] == '1') 14 | {//문자열의 처음이 1일 경우에 xor 연산 수행 15 | for (int j = 0; j < GENERATOR.length(); j++) 16 | { 17 | if ((tempFrame[j] ^ GENERATOR[j]) == 0) 18 | tempFrame.replace(j, 1, "0"); // gen과 XOR 연산 결과 0일경우 해당 문자열의 인덱스를 0으로 교체 19 | else if ((tempFrame[j] ^ GENERATOR[j]) == 1) 20 | tempFrame.replace(j, 1, "1");// GEN과 XOR 연산 결과 1일 경우 해당 문자열의 인덱스를 1로 교체 21 | } 22 | 23 | } 24 | while (tempFrame[0] == '0') {// 문자열의 처음이 1이 될때까지 문자열 최상위의 0을 제거함. 이 연산 이후 문자열의 길이가 짧아짐. 25 | tempFrame.erase(0, 1); 26 | } 27 | } 28 | return tempFrame; // mod-2연산을 통해 가공된 문자열 반환(mod-2 연산의remainder) 29 | 30 | } 31 | 32 | int main(){ 33 | /* 변수 선언 */ 34 | string FRAME; // 전송된 FRAME 표준 입력을 통해 verifier로 넘어옴. 35 | string GENERATOR; // 전송된 GEN, 표준 입력을 통해 verifier로 넘어옴. 36 | string remainder; // FRAME을 GEN으로 MOD-2 연산결과 저장 변수 37 | 38 | /*line 단위 표준 입력*/ 39 | getline(cin,FRAME); 40 | getline(cin,GENERATOR); 41 | 42 | /*remainder string에 mod2 결과 저장*/ 43 | remainder=mod2Op(FRAME,GENERATOR); 44 | 45 | /*remaider의 상태에 따라 error 여부 결정-remainder 발생시 error message 출력*/ 46 | if(remainder==""){ 47 | cout << "received : " << FRAME << endl; 48 | cout << "GENERATOR : " << GENERATOR << endl; 49 | cout << "remainder : " << remainder << endl; 50 | cout << "no error detected!" << endl; 51 | } 52 | else { 53 | cout << "received : " << FRAME << endl; 54 | cout << "GENERATOR : " << GENERATOR << endl; 55 | cout << "remainder : " << remainder << endl; 56 | cout << "error detected!" << endl; 57 | } 58 | 59 | return 0; 60 | 61 | } 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Data-Communication-2019-2 2 | 19년도 2학기 동국대학교 컴퓨터공학과 데이터통신 어사인먼트입니다. 3 | 19년도에 수행한 코드를 학습 및 후배들의 과제 수행에 도움이 되라고 올립니다. 4 | 5 | ## Assignment#1 (CDMA) 6 | - ### 문제정의 7 | >write a program to implement CDMA. assume that the length of a chip sequences is eight process and the number of stations transmitting is four. your program consists of three sets of process, four transmitter process(t0,t1,t2 and t3), one joiner process, and four receiver process (r0,r1,r2 and r3). The main program, which also acts as the joiner process, first reads four chip sequences ( bipolar notation ) from the standard input and a sequence of 4 bits ( 1bit per transmitter process to be transmitted), and forks off four pairs of transmitter and receiver process,. each pair of transmitter/receiver processes (t0,r0; t1,r1; t2,r2; t3,r3) is assigned one chip sequence and each transmitter process is assigned 1 bit (first bit to t0, second bit to t1 and so on). Next each transmitter computes the signal to be transmitted (a sequence of 8bits) and sends it to the joiner process. After receiving signals from all four transmitter processes, the joiner process combines the signals and sends the combined signal to four receiver processes. Each receiver process then computes the bit it has received and prints it to standard output. use pipes for communication between processes. 8 | 9 | - ### 어싸인 수행에 필요한 것 10 | - Code Division Multiple Access에 대한 이해 11 | - LINUX 시스템에서 지원하는 fork() 에 대한 프로세스-스레드 개념이해 12 | - 프로세스간 통신에 이용되는 Pipe에 대한 이해 13 | - ### 채점기준 14 | - 코드의 정상작동 15 | - 코드의 논리적 구조와 설계 16 | - fork, pipe 등의 사용여부 17 | - 코드의 가독성 및 주석의 상세함을 통한 유지보수성 18 | - ### 실행 결과 19 | ![1](https://user-images.githubusercontent.com/57410044/100576266-273a4680-3321-11eb-8177-456ba3b54f1f.PNG) 20 | ![2](https://user-images.githubusercontent.com/57410044/100576492-9a43bd00-3321-11eb-9ed2-bff981d80a95.PNG) 21 | ![3](https://user-images.githubusercontent.com/57410044/100576502-a0399e00-3321-11eb-8652-af8e75fe4121.PNG) 22 | ![4](https://user-images.githubusercontent.com/57410044/100576508-a465bb80-3321-11eb-8146-05f6c0801e56.PNG) 23 | ![5](https://user-images.githubusercontent.com/57410044/100576517-a9c30600-3321-11eb-8f94-5d05d10fb345.PNG) 24 | 25 | ## Assignment#2 (CRC) 26 | 27 | 28 | - ### 문제정의 29 | >36. the goal of this lab exercise is to implement an error-detection mechanism using the standard CRC algorithm described in the text. Write two programs, generator and verifier. The generator program reads from standard input a line of ASCII text containing an n-bit message consisting of a string of 0s and 1s. The second line is the k-bit polynominal, also in ASCII. It outputs to standard a line of ASCII text with n+k 0s and 1s representing the message to be transmitted. Then, it outputs the polynominal, just as it read it in. the verifier program reads in the outputs a message indicating whether it is correct or not, finally write a program, alter, that inverts 1bit on the first line depending on its argument(the bit number counting the leftmost bit as 1) but copies the rest of the two lines correctly. 30 | By typing 31 | Generator 비정상 실행 46 | ![6](https://user-images.githubusercontent.com/57410044/100576538-b3e50480-3321-11eb-8190-c6d625f04689.PNG) 47 | 48 | >정상실행 49 | ![7](https://user-images.githubusercontent.com/57410044/100576563-bba4a900-3321-11eb-88d7-7db6a101da46.PNG) 50 | 51 | >file.png 52 | ![file](https://user-images.githubusercontent.com/57410044/100576591-c7906b00-3321-11eb-936c-ebc08ea294cb.PNG) 53 | -------------------------------------------------------------------------------- /Assignment#1/2015112167CDMA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define BUFSIZE 60 9 | using namespace std; 10 | /*transmitter class - each input station & sendingbit*/ 11 | class transmitter 12 | { 13 | int station[8] = {0}; 14 | int temp[8] = {0}; 15 | int tempBit = -1; //status 1,0 16 | public: 17 | transmitter(){cout<<"generate transmitter!"<tempBit = bit;}; // setting input bit; 20 | int* getSequence(); // return calculated transmitter's sequence!! 21 | }; 22 | void transmitter::setStation(int *arr) 23 | { 24 | for(int i=0;i<8;i++) 25 | { 26 | this->station[i] = arr[i]; 27 | } 28 | } 29 | 30 | int* transmitter::getSequence(){ 31 | 32 | //int this->temp[8]={0}; 33 | for(int i=0;i<8; i++) // station copy 34 | { 35 | this->temp[i]=this->station[i]; 36 | } 37 | if(this->tempBit==0) // if this transmitter's input bit is 0 then, bosu sending 38 | { 39 | for(int i=0;i<8;i++) 40 | { 41 | this->temp[i] = this->temp[i] *(-1); 42 | } 43 | return this->temp; 44 | } 45 | else if(this->tempBit==1) // if this transmitter's input bit is 1 then, return stationvalue 46 | { 47 | for(int i=0;i<8;i++) 48 | { 49 | this->temp[i] = this->temp[i] *(1); 50 | } 51 | return this->temp; 52 | } 53 | } 54 | /*receiver class - each input station & from joiner sigma of seq*/ 55 | 56 | class receiver 57 | { 58 | int station[8] = {0}; 59 | int inputBit[8] = {0}; //input S from joiner 60 | int outputBit = 0; //finally returned 61 | public: 62 | receiver(){cout<<"generate receiver!"<outputBit;}; 66 | void calculateOut(); 67 | }; 68 | void receiver::setStation(int *arr) 69 | { 70 | for(int i=0;i<8;i++) 71 | { 72 | this->station[i] = arr[i]; 73 | } 74 | } 75 | void receiver::inputSumming(int *arr) 76 | { 77 | for(int i=0;i<8;i++) 78 | { 79 | this->inputBit[i]=arr[i]; 80 | } 81 | } 82 | void receiver::calculateOut() 83 | { 84 | int temp=0; 85 | for(int i=0; i<8 ; i++) 86 | { //innerproduct 87 | temp=temp+(this->station[i])*(this->inputBit[i]); 88 | } 89 | if(temp/8==(-1)) // if temp is -1 then, change 0 because of unity. 90 | { 91 | this->outputBit=0; 92 | } 93 | else 94 | { 95 | this->outputBit=temp/8; 96 | } 97 | } 98 | 99 | int main() 100 | 101 | { 102 | cout<<"<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>" << endl; 103 | cout<<"<>" << endl; 104 | cout<<"<<<<<<<<<<<<>>>>>>>>>>>>>>>" << endl; 105 | 106 | /* sets of transmitter and joiner pipes */ 107 | int tfds00[2], tfds01[2], tfds10[2], tfds11[2], tfds20[2], tfds21[2], tfds30[2], tfds31[2]; 108 | /* sets of receiver and joiner pipes */ 109 | int rfds00[2], rfds01[2], rfds10[2], rfds11[2], rfds20[2], rfds21[2], rfds30[2], rfds31[2]; 110 | 111 | int summing[8]={0}; // Joiners Sigma 112 | int buf[BUFSIZE]; 113 | 114 | pid_t trans_pid[4]; // transmitter process arr 115 | pid_t receive_pid[4]; //receiver process arr 116 | 117 | int stationA[8]={0}; 118 | int stationB[8]={0}; 119 | int stationC[8]={0}; 120 | int stationD[8]={0};//station array 121 | 122 | int sendingBits[4]={0}; //bits to transmitter 123 | int outputBits[4]={0}; // output bits if it is same as outputBits, then success CDMA 124 | pipe(tfds00),pipe(tfds01),pipe(tfds10),pipe(tfds11),pipe(tfds20),pipe(tfds21),pipe(tfds30),pipe(tfds31); 125 | pipe(rfds00),pipe(rfds01),pipe(rfds10),pipe(rfds11),pipe(rfds20),pipe(rfds21),pipe(rfds30),pipe(rfds31); 126 | 127 | 128 | // from user input CDMA stations 129 | 130 | for(int j=0;j<8;j++) 131 | { 132 | cout << "stationA" <<"[" << j <<"] : " ; 133 | cin >> stationA[j]; 134 | cout << endl; 135 | } 136 | for(int j=0;j<8;j++) 137 | { 138 | cout << "stationB" <<"[" << j <<"] : " ; 139 | cin >> stationB[j]; 140 | cout << endl; 141 | } 142 | for(int j=0;j<8;j++) 143 | { 144 | cout << "stationC" <<"[" << j <<"] : " ; 145 | cin >> stationC[j]; 146 | cout << endl; 147 | } 148 | for(int j=0;j<8;j++) 149 | { 150 | cout << "stationD" <<"[" << j <<"] : " ; 151 | cin >> stationD[j]; 152 | cout << endl; 153 | } 154 | //inputting sending bit 155 | cout << " <<<>>>" << endl; 156 | cout << " <<<<<<< please input 1 or 0 >>>>>>>>>>" << endl; 157 | for(int i =0 ; i<4 ; i++) 158 | { cout << "bit[" << i <<"] : "; 159 | cin >> sendingBits[i];} 160 | 161 | // transmiting process forking 162 | 163 | 164 | 165 | trans_pid[0]=fork(); //stationA 166 | if(trans_pid[0]==0) 167 | { // it execute at jasic process 168 | cout << getpid() << "is forking!" << endl; 169 | read(tfds01[0],buf,BUFSIZE); // pipe reading for setting station 170 | transmitter A = transmitter(); // instance generating 171 | A.setStation(buf); // set. 172 | read(tfds01[0],buf,BUFSIZE); //pipe reading for setting inputbit 173 | A.inputBit(buf[0]); 174 | int * p = A.getSequence(); 175 | write(tfds00[1],p,BUFSIZE); 176 | cout << "transmitterA is sending to joiner" << " : "; 177 | for(int i=0;i<8;i++) 178 | { 179 | cout << *(p + i) << " "; 180 | } 181 | cout << endl; 182 | ; 183 | exit(getpid()); 184 | } 185 | else{ //it execute at parents process 186 | write(tfds01[1],stationA,BUFSIZE);// piple writting for setting station 187 | sleep(1); 188 | int temp = sendingBits[0]; 189 | write(tfds01[1],&temp,BUFSIZE); // pipe writting for setting inputbit 190 | read(tfds00[0],buf,BUFSIZE); 191 | for(int k = 0; k<8 ; k++) 192 | { 193 | summing[k]=summing[k]+buf[k]; 194 | 195 | } 196 | 197 | } 198 | 199 | 200 | 201 | 202 | trans_pid[1]=fork(); //stationB 203 | if(trans_pid[1]==0) 204 | { 205 | cout << getpid() << "is forking!" << endl; 206 | read(tfds11[0],buf,BUFSIZE); 207 | transmitter B = transmitter(); 208 | B.setStation(buf); 209 | read(tfds11[0],buf,BUFSIZE); 210 | B.inputBit(buf[0]); 211 | int * p = B.getSequence(); 212 | write(tfds10[1],p,BUFSIZE); 213 | cout << "transmitterB is sending to joiner" << " : "; 214 | for(int i=0;i<8;i++) 215 | { 216 | cout << *(p + i) << " "; 217 | }cout << endl; 218 | 219 | exit(getpid()); 220 | } 221 | else{ 222 | write(tfds11[1],stationB,BUFSIZE); 223 | sleep(1); 224 | int temp = sendingBits[1]; 225 | write(tfds11[1],&temp,BUFSIZE); 226 | read(tfds10[0],buf,BUFSIZE); 227 | for(int k = 0; k<8 ; k++) 228 | { 229 | summing[k]=summing[k]+buf[k]; 230 | 231 | } 232 | } 233 | 234 | 235 | 236 | 237 | 238 | trans_pid[2]=fork(); //stationC 239 | if(trans_pid[2]==0) 240 | { 241 | cout << getpid() << "is forking!" << endl; 242 | read(tfds21[0],buf,BUFSIZE); 243 | transmitter C = transmitter(); 244 | C.setStation(buf); 245 | read(tfds21[0],buf,BUFSIZE); 246 | C.inputBit(buf[0]); 247 | int * p = C.getSequence(); 248 | write(tfds20[1],p,BUFSIZE); 249 | cout << "transmitterC is sending to joiner" << " : "; 250 | for(int i=0;i<8;i++) 251 | { 252 | cout << *(p + i) << " "; 253 | }cout << endl; 254 | 255 | exit(getpid()); 256 | } 257 | else{ 258 | write(tfds21[1],stationC,BUFSIZE); 259 | sleep(1); 260 | int temp = sendingBits[2]; 261 | write(tfds21[1],&temp,BUFSIZE); 262 | read(tfds20[0],buf,BUFSIZE); 263 | for(int k = 0; k<8 ; k++) 264 | { 265 | summing[k]=summing[k]+buf[k]; 266 | 267 | } 268 | } 269 | 270 | 271 | 272 | 273 | 274 | trans_pid[3]=fork(); //stationD 275 | if(trans_pid[3]==0) 276 | { 277 | cout << getpid() << "is forking!" << endl; 278 | read(tfds31[0],buf,BUFSIZE); 279 | transmitter D = transmitter(); 280 | D.setStation(buf); 281 | read(tfds31[0],buf,BUFSIZE); 282 | D.inputBit(buf[0]); 283 | int * p = D.getSequence(); 284 | cout << "transmitterD is sending to joiner" << " : "; 285 | write(tfds30[1],p,BUFSIZE); 286 | for(int i=0;i<8;i++) 287 | { 288 | cout << *(p + i) << " "; 289 | }cout << endl; 290 | 291 | exit(getpid()); 292 | } 293 | else{ 294 | write(tfds31[1],stationD,BUFSIZE); 295 | sleep(1); 296 | int temp = sendingBits[3]; 297 | write(tfds31[1],&temp,BUFSIZE); 298 | read(tfds30[0],buf,BUFSIZE); 299 | for(int k = 0; k<8 ; k++) 300 | { 301 | summing[k]=summing[k]+buf[k]; 302 | 303 | } 304 | } 305 | 306 | 307 | 308 | 309 | //transprocess can't access here 310 | if(trans_pid[0]!=0&&trans_pid[1]!=0&&trans_pid[2]!=0&&trans_pid[3]!=0) 311 | { 312 | 313 | //summing all signal from transmitter; 314 | sleep(2); 315 | cout << "S = ("; 316 | for(int i = 0; i<8 ; i++) 317 | { 318 | cout<