Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pcom-laboratoare-public
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Clara-Maria CIARNĂU (78551)
pcom-laboratoare-public
Commits
e34b3151
Commit
e34b3151
authored
2 years ago
by
Vlad-Andrei BĂDOIU (78692)
Browse files
Options
Downloads
Patches
Plain Diff
lab2: Update skeleton to match text
parent
c1971cc1
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
lab2/README.md
+19
-7
19 additions, 7 deletions
lab2/README.md
lab2/common.h
+10
-0
10 additions, 0 deletions
lab2/common.h
lab2/recv.c
+24
-8
24 additions, 8 deletions
lab2/recv.c
lab2/send.c
+28
-8
28 additions, 8 deletions
lab2/send.c
with
81 additions
and
23 deletions
lab2/README.md
+
19
−
7
View file @
e34b3151
Physical layer simulator.
Physical layer simulator. We have
**two separate programs**
, the sender and the receiver.
Normally, we would implement our protocol as a library, but to make things
easier, we implement part of the protocol in send.c, and the receving code in
recv.c.
``send.c``
- the code that the sender will execute
``recv.c``
- the code that the receiver on the other end of the wire will execute
``common.h``
- header where we define the
`Frame`
structure
``common.h``
- header where we define the
`Frame`
structure
and the API that the physical layers exports
Overview of the architecture
```
sender receiver
| |
|______________________|
Physical (wire)
sender receiver
| |
Physical layer Physical layer
protocol protocol
|______________________|
Physical (wire)
```
Note, if you want to use C++, simply change the extension of the
`send.c`
and
`recv.c`
to
`.cpp`
and update the Makefile.
## C++
Note, if you want to use C++, simply change the extension of the
`send.c`
and
`recv.c`
to
`.cpp`
and update the Makefile to use
`g++`
.
## API
```
...
...
@@ -30,3 +39,6 @@ make
```
We will run the sender and receiver in parallel using
``run_experiment.sh``
.
This scripts first runs the receiver binary and then runs the sender binary.
There are several parameters that can be used to modify the characteristics of
the link, but we don't need them for this lab.
This diff is collapsed.
Click to expand it.
lab2/common.h
+
10
−
0
View file @
e34b3151
#define DLE (char)0
#define STX (char)2
#define ETX (char)3
/* Atributul este folosit pentru a anunta compilatorul sa nu alinieze structura */
__attribute__
((
packed
))
/* DELIM | DATE | DELIM */
struct
Frame
{
char
frame_delim_start
[
2
];
/* DEL STX */
/* TODO 2: Add source and destination */
char
payload
[
30
];
/* Datele pe care vrem sa le transmitem */
char
frame_delim_end
[
2
];
/* DEL ETX */
};
/* Sends one character to the other end via the Physical layer */
int
send_byte
(
char
c
);
/* Receives one character from the other end, if nothing is sent by the other end, returns a random character */
char
recv_byte
();
This diff is collapsed.
Click to expand it.
lab2/recv.c
+
24
−
8
View file @
e34b3151
...
...
@@ -5,17 +5,34 @@
#include
<fcntl.h>
#include
"link_emulator/lib.h"
/* Do not touch these two */
#define HOST "127.0.0.1"
#define PORT 10001
#include
"common.h"
#define DLE (char)0
#define STX (char)2
#define ETX (char)3
/* TODO 2: write recv_frame function */
/* Our unqiue layer 2 ID */
static
int
ID
=
123131
;
/* Function which our protocol implementation will provide to the upper layer. */
int
recv_frame
(
char
*
buf
,
int
size
)
{
/* TODO 1.1: Call recv_byte() until we receive the frame start
* delimitator. This operation makes this function blocking until it
* receives a frame. */
/* TODO 2.1: The first two 2 * sizeof(int) bytes represent sender and receiver ID */
/* TODO 2.2: Check that the frame was sent to me */
/* TODO 1.2: Read bytes and copy them to buff until we receive the end of the frame */
/* If everything went well return the number of bytes received */
return
0
;
}
int
main
(
int
argc
,
char
**
argv
){
/* Do not touch this */
init
(
HOST
,
PORT
);
...
...
@@ -52,12 +69,11 @@ int main(int argc,char** argv){
c
=
recv_byte
();
printf
(
"%c
\n
"
,
c
);
/* TODO 1.0: Allocate a buffer and call recv_frame */
/* TODO 2: Run the receiver until you receive the frame DONE */
/* TODO 3: receive a frame with a structure of type Pa */
/* TODO 4: Measure latency in a while loop for any frame that contains a timestamp we receive, print frame_size and latency */
/* TODO 3: Measure latency in a while loop for any frame that contains
* a timestamp we receive, print frame_size and latency */
printf
(
"[RECEIVER] Finished transmission
\n
"
);
return
0
;
...
...
This diff is collapsed.
Click to expand it.
lab2/send.c
+
28
−
8
View file @
e34b3151
...
...
@@ -13,13 +13,29 @@
/* Here we have the Frame structure */
#include
"common.h"
#define DLE (char)0
#define STX (char)2
#define ETX (char)3
/* TODO 2: implement send_frame function */
/* Our unqiue layer 2 ID */
static
int
ID
=
123131
;
/* Function which our protocol implementation will provide to the upper layer. */
int
send_frame
(
char
*
buf
,
int
size
)
{
/* TODO 1.1: Create a new frame. */
/* TODO 1.2: Copy the data from buffer to our frame structure */
/* TODO 2.1: Set the destination and source */
/* TODO 1.3: We can cast the frame to a char *, and iterate through sizeof(struct Frame) bytes
calling send_bytes. */
/* if all went all right, return 0 */
return
0
;
}
int
main
(
int
argc
,
char
**
argv
){
// Don't touch this
init
(
HOST
,
PORT
);
/* Send Hello */
...
...
@@ -31,12 +47,16 @@ int main(int argc,char** argv){
send_byte
(
'l'
);
send_byte
(
'o'
);
send_byte
(
'!'
);
send_byte
(
DLE
);
send_byte
(
ETX
);
/* TODO 1.0: Get some input in a buffer and call send_frame with it */
/* TODO 3.1: Get a timestamp of the current time copy it in the the payload */
/* TODO
2: call send_frame function with a given string input
*/
/* TODO
3.0: Upload the maximum size of the payload in Frame to 100, send the frame
*/
/* TODO 3
: use send_frame to send a structure of type Packet
*/
/* TODO 3
.0: Upload the maximum size of the payload in Frame to 300, send the frame
*/
/* TODO 4: send 100 bytes, send 300 bytes, append a timestamp to these frames */
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment