Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-RAN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
canghaiwuhen
OpenXG-RAN
Commits
25ab1c35
Commit
25ab1c35
authored
Oct 20, 2016
by
luhan wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modifications for if4p5 UDP
parent
9b9a7e50
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
487 additions
and
482 deletions
+487
-482
targets/ARCH/ETHERNET/USERSPACE/LIB/eth_udp.c
targets/ARCH/ETHERNET/USERSPACE/LIB/eth_udp.c
+487
-482
No files found.
targets/ARCH/ETHERNET/USERSPACE/LIB/eth_udp.c
View file @
25ab1c35
/*******************************************************************************
/*******************************************************************************
OpenAirInterface
OpenAirInterface
Copyright(c) 1999 - 2014 Eurecom
Copyright(c) 1999 - 2014 Eurecom
OpenAirInterface is free software: you can redistribute it and/or modify
OpenAirInterface is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
OpenAirInterface is distributed in the hope that it will be useful,
OpenAirInterface is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with OpenAirInterface.The full GNU General Public License is
along with OpenAirInterface.The full GNU General Public License is
included in this distribution in the file called "COPYING". If not,
included in this distribution in the file called "COPYING". If not,
see <http://www.gnu.org/licenses/>.
see <http://www.gnu.org/licenses/>.
Contact Information
Contact Information
OpenAirInterface Admin: openair_admin@eurecom.fr
OpenAirInterface Admin: openair_admin@eurecom.fr
OpenAirInterface Tech : openair_tech@eurecom.fr
OpenAirInterface Tech : openair_tech@eurecom.fr
OpenAirInterface Dev : openair4g-devel@lists.eurecom.fr
OpenAirInterface Dev : openair4g-devel@lists.eurecom.fr
Address : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
Address : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
*******************************************************************************/
*******************************************************************************/
/*! \file ethernet_lib.c
/*! \file ethernet_lib.c
* \brief API to stream I/Q samples over standard ethernet
* \brief API to stream I/Q samples over standard ethernet
* \author add alcatel Katerina Trilyraki, Navid Nikaein, Pedro Dinis, Lucio Ferreira, Raymond Knopp
* \author add alcatel Katerina Trilyraki, Navid Nikaein, Pedro Dinis, Lucio Ferreira, Raymond Knopp
* \date 2015
* \date 2015
* \version 0.2
* \version 0.2
* \company Eurecom
* \company Eurecom
* \maintainer: navid.nikaein@eurecom.fr
* \maintainer: navid.nikaein@eurecom.fr
* \note
* \note
* \warning
* \warning
*/
*/
#include <arpa/inet.h>
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <linux/if_packet.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if.h>
#include <netinet/ether.h>
#include <netinet/ether.h>
#include <unistd.h>
#include <unistd.h>
#include <errno.h>
#include <errno.h>
#include "vcd_signal_dumper.h"
#include "vcd_signal_dumper.h"
#include "common_lib.h"
#include "common_lib.h"
#include "ethernet_lib.h"
#include "ethernet_lib.h"
#define DEBUG 0
#define DEBUG 0
struct
sockaddr_in
dest_addr
[
MAX_INST
];
struct
sockaddr_in
dest_addr
[
MAX_INST
];
struct
sockaddr_in
local_addr
[
MAX_INST
];
struct
sockaddr_in
local_addr
[
MAX_INST
];
int
addr_len
[
MAX_INST
];
int
addr_len
[
MAX_INST
];
uint16_t
pck_seq_num
=
1
;
uint16_t
pck_seq_num
=
1
;
uint16_t
pck_seq_num_cur
=
0
;
uint16_t
pck_seq_num_cur
=
0
;
uint16_t
pck_seq_num_prev
=
0
;
uint16_t
pck_seq_num_prev
=
0
;
int
eth_socket_init_udp
(
openair0_device
*
device
)
{
int
eth_socket_init_udp
(
openair0_device
*
device
)
{
int
i
=
0
;
int
i
=
0
;
eth_state_t
*
eth
=
(
eth_state_t
*
)
device
->
priv
;
eth_state_t
*
eth
=
(
eth_state_t
*
)
device
->
priv
;
int
Mod_id
=
device
->
Mod_id
;
int
Mod_id
=
device
->
Mod_id
;
char
str_local
[
INET_ADDRSTRLEN
];
char
str_local
[
INET_ADDRSTRLEN
];
char
str_remote
[
INET_ADDRSTRLEN
];
char
str_remote
[
INET_ADDRSTRLEN
];
const
char
*
local_ip
,
*
remote_ip
;
const
char
*
local_ip
,
*
remote_ip
;
int
local_port
=
0
,
remote_port
=
0
;
int
local_port
=
0
,
remote_port
=
0
;
int
sock_dom
=
0
;
int
sock_dom
=
0
;
int
sock_type
=
0
;
int
sock_type
=
0
;
int
sock_proto
=
0
;
int
sock_proto
=
0
;
int
enable
=
1
;
int
enable
=
1
;
if
(
device
->
host_type
==
RRH_HOST
)
{
if
(
device
->
host_type
==
RRH_HOST
)
{
local_ip
=
device
->
openair0_cfg
->
my_addr
;
local_ip
=
device
->
openair0_cfg
->
my_addr
;
local_port
=
device
->
openair0_cfg
->
my_port
;
local_port
=
device
->
openair0_cfg
->
my_port
;
remote_ip
=
"0.0.0.0"
;
remote_ip
=
"0.0.0.0"
;
remote_port
=
0
;
remote_port
=
0
;
printf
(
"[%s] local ip addr %s port %d
\n
"
,
"RRH"
,
local_ip
,
local_port
);
printf
(
"[%s] local ip addr %s port %d
\n
"
,
"RRH"
,
local_ip
,
local_port
);
}
else
{
}
else
{
local_ip
=
device
->
openair0_cfg
->
my_addr
;
local_ip
=
device
->
openair0_cfg
->
my_addr
;
local_port
=
device
->
openair0_cfg
->
my_port
;
local_port
=
device
->
openair0_cfg
->
my_port
;
remote_ip
=
device
->
openair0_cfg
->
remote_addr
;
remote_ip
=
device
->
openair0_cfg
->
remote_addr
;
remote_port
=
device
->
openair0_cfg
->
remote_port
;
remote_port
=
device
->
openair0_cfg
->
remote_port
;
printf
(
"[%s] local ip addr %s port %d
\n
"
,
"BBU"
,
local_ip
,
local_port
);
printf
(
"[%s] local ip addr %s port %d
\n
"
,
"BBU"
,
local_ip
,
local_port
);
}
}
/* Open socket to send on */
/* Open socket to send on */
sock_dom
=
AF_INET
;
sock_dom
=
AF_INET
;
sock_type
=
SOCK_DGRAM
;
sock_type
=
SOCK_DGRAM
;
sock_proto
=
IPPROTO_UDP
;
sock_proto
=
IPPROTO_UDP
;
if
((
eth
->
sockfd
[
Mod_id
]
=
socket
(
sock_dom
,
sock_type
,
sock_proto
))
==
-
1
)
{
if
((
eth
->
sockfd
[
Mod_id
]
=
socket
(
sock_dom
,
sock_type
,
sock_proto
))
==
-
1
)
{
perror
(
"ETHERNET: Error opening socket"
);
perror
(
"ETHERNET: Error opening socket"
);
exit
(
0
);
exit
(
0
);
}
}
/* initialize addresses */
/* initialize addresses */
for
(
i
=
0
;
i
<
MAX_INST
;
i
++
)
{
for
(
i
=
0
;
i
<
MAX_INST
;
i
++
)
{
bzero
((
void
*
)
&
(
dest_addr
[
i
]),
sizeof
(
dest_addr
[
i
]));
bzero
((
void
*
)
&
(
dest_addr
[
i
]),
sizeof
(
dest_addr
[
i
]));
bzero
((
void
*
)
&
(
local_addr
[
i
]),
sizeof
(
local_addr
[
i
]));
bzero
((
void
*
)
&
(
local_addr
[
i
]),
sizeof
(
local_addr
[
i
]));
}
}
addr_len
[
Mod_id
]
=
sizeof
(
struct
sockaddr_in
);
addr_len
[
Mod_id
]
=
sizeof
(
struct
sockaddr_in
);
dest_addr
[
Mod_id
].
sin_family
=
AF_INET
;
dest_addr
[
Mod_id
].
sin_family
=
AF_INET
;
inet_pton
(
AF_INET
,
remote_ip
,
&
(
dest_addr
[
Mod_id
].
sin_addr
.
s_addr
));
inet_pton
(
AF_INET
,
remote_ip
,
&
(
dest_addr
[
Mod_id
].
sin_addr
.
s_addr
));
dest_addr
[
Mod_id
].
sin_port
=
htons
(
remote_port
);
dest_addr
[
Mod_id
].
sin_port
=
htons
(
remote_port
);
inet_ntop
(
AF_INET
,
&
(
dest_addr
[
Mod_id
].
sin_addr
),
str_remote
,
INET_ADDRSTRLEN
);
inet_ntop
(
AF_INET
,
&
(
dest_addr
[
Mod_id
].
sin_addr
),
str_remote
,
INET_ADDRSTRLEN
);
local_addr
[
Mod_id
].
sin_family
=
AF_INET
;
local_addr
[
Mod_id
].
sin_family
=
AF_INET
;
inet_pton
(
AF_INET
,
local_ip
,
&
(
local_addr
[
Mod_id
].
sin_addr
.
s_addr
));
inet_pton
(
AF_INET
,
local_ip
,
&
(
local_addr
[
Mod_id
].
sin_addr
.
s_addr
));
local_addr
[
Mod_id
].
sin_port
=
htons
(
local_port
);
local_addr
[
Mod_id
].
sin_port
=
htons
(
local_port
);
inet_ntop
(
AF_INET
,
&
(
local_addr
[
Mod_id
].
sin_addr
),
str_local
,
INET_ADDRSTRLEN
);
inet_ntop
(
AF_INET
,
&
(
local_addr
[
Mod_id
].
sin_addr
),
str_local
,
INET_ADDRSTRLEN
);
/* set reuse address flag */
/* set reuse address flag */
if
(
setsockopt
(
eth
->
sockfd
[
Mod_id
],
SOL_SOCKET
,
SO_REUSEADDR
,
&
enable
,
sizeof
(
int
)))
{
if
(
setsockopt
(
eth
->
sockfd
[
Mod_id
],
SOL_SOCKET
,
SO_REUSEADDR
,
&
enable
,
sizeof
(
int
)))
{
perror
(
"ETHERNET: Cannot set SO_REUSEADDR option on socket"
);
perror
(
"ETHERNET: Cannot set SO_REUSEADDR option on socket"
);
exit
(
0
);
exit
(
0
);
}
}
/* want to receive -> so bind */
/* want to receive -> so bind */
if
(
bind
(
eth
->
sockfd
[
Mod_id
],(
struct
sockaddr
*
)
&
local_addr
[
Mod_id
],
addr_len
[
Mod_id
])
<
0
)
{
if
(
bind
(
eth
->
sockfd
[
Mod_id
],(
struct
sockaddr
*
)
&
local_addr
[
Mod_id
],
addr_len
[
Mod_id
])
<
0
)
{
perror
(
"ETHERNET: Cannot bind to socket"
);
perror
(
"ETHERNET: Cannot bind to socket"
);
exit
(
0
);
exit
(
0
);
}
else
{
}
else
{
printf
(
"[%s] binding mod_%d to %s:%d
\n
"
,
"RRH"
,
Mod_id
,
str_local
,
ntohs
(
local_addr
[
Mod_id
].
sin_port
));
printf
(
"[%s] binding mod_%d to %s:%d
\n
"
,
"RRH"
,
Mod_id
,
str_local
,
ntohs
(
local_addr
[
Mod_id
].
sin_port
));
}
}
return
0
;
return
0
;
}
}
int
trx_eth_read_udp_IF4p5
(
openair0_device
*
device
,
openair0_timestamp
*
timestamp
,
void
**
buff
,
int
nsamps
,
int
cc
)
{
int
trx_eth_read_udp_IF4p5
(
openair0_device
*
device
,
openair0_timestamp
*
timestamp
,
void
**
buff
,
int
nsamps
,
int
cc
)
{
// Read nblocks info from packet itself
// Read nblocks info from packet itself
int
nblocks
=
nsamps
;
int
nblocks
=
nsamps
;
int
bytes_received
=
0
;
int
bytes_received
=-
1
;
eth_state_t
*
eth
=
(
eth_state_t
*
)
device
->
priv
;
eth_state_t
*
eth
=
(
eth_state_t
*
)
device
->
priv
;
int
Mod_id
=
device
->
Mod_id
;
int
Mod_id
=
device
->
Mod_id
;
ssize_t
packet_size
=
sizeof_IF4p5_header_t
;
ssize_t
packet_size
=
sizeof_IF4p5_header_t
;
IF4p5_header_t
*
test_header
=
(
IF4p5_header_t
*
)(
buff
[
0
]);
IF4p5_header_t
*
test_header
=
(
IF4p5_header_t
*
)(
buff
[
0
]);
int
block_cnt
=
0
;
bytes_received
=
recvfrom
(
eth
->
sockfd
[
Mod_id
],
int
again_cnt
=
0
;
buff
[
0
],
packet_size
=
max
(
UDP_IF4p5_PRACH_SIZE_BYTES
,
max
(
UDP_IF4p5_PULFFT_SIZE_BYTES
(
nblocks
),
UDP_IF4p5_PDLFFT_SIZE_BYTES
(
nblocks
)));
packet_size
,
0
,
while
(
bytes_received
==
-
1
)
{
(
struct
sockaddr
*
)
&
dest_addr
[
Mod_id
],
again:
(
socklen_t
*
)
&
addr_len
[
Mod_id
]);
bytes_received
=
recvfrom
(
eth
->
sockfd
[
Mod_id
],
buff
[
0
],
if
(
bytes_received
==-
1
)
{
packet_size
,
eth
->
num_rx_errors
++
;
0
,
perror
(
"ETHERNET IF4p5 READ (header): "
);
(
struct
sockaddr
*
)
&
dest_addr
[
Mod_id
],
exit
(
-
1
);
(
socklen_t
*
)
&
addr_len
[
Mod_id
]);
}
if
(
bytes_received
==-
1
)
{
eth
->
num_rx_errors
++
;
*
timestamp
=
test_header
->
sub_type
;
if
(
errno
==
EAGAIN
)
{
again_cnt
++
;
if
(
test_header
->
sub_type
==
IF4p5_PDLFFT
)
{
usleep
(
10
);
packet_size
=
UDP_IF4p5_PDLFFT_SIZE_BYTES
(
nblocks
);
if
(
again_cnt
==
1000
)
{
}
else
if
(
test_header
->
sub_type
==
IF4p5_PULFFT
)
{
perror
(
"ETHERNET IF4p5 READ (EAGAIN): "
);
packet_size
=
UDP_IF4p5_PULFFT_SIZE_BYTES
(
nblocks
);
exit
(
-
1
);
}
else
{
}
else
{
packet_size
=
UDP_IF4p5_PRACH_SIZE_BYTES
;
printf
(
"AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN
\n
"
);
}
goto
again
;
}
}
else
if
(
errno
==
EWOULDBLOCK
)
{
while
(
bytes_received
<
packet_size
)
{
block_cnt
++
;
bytes_received
=
recvfrom
(
eth
->
sockfd
[
Mod_id
],
usleep
(
10
);
buff
[
0
],
if
(
block_cnt
==
1000
)
{
packet_size
,
perror
(
"ETHERNET IF4p5 READ (EWOULDBLOCK): "
);
0
,
exit
(
-
1
);
(
struct
sockaddr
*
)
&
dest_addr
[
Mod_id
],
}
else
{
(
socklen_t
*
)
&
addr_len
[
Mod_id
]);
printf
(
"BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK
\n
"
);
if
(
bytes_received
==-
1
)
{
goto
again
;
eth
->
num_rx_errors
++
;
}
perror
(
"ETHERNET IF4p5 READ (payload): "
);
}
else
{
exit
(
-
1
);
perror
(
"ETHERNET IF4p5 READ"
);
}
else
{
printf
(
"(%s):
\n
"
,
strerror
(
errno
));
eth
->
rx_actual_nsamps
=
bytes_received
>>
1
;
exit
(
-
1
);
eth
->
rx_count
++
;
}
}
}
else
{
}
*
timestamp
=
test_header
->
sub_type
;
eth
->
rx_actual_nsamps
=
bytes_received
>>
1
;
eth
->
rx_nsamps
=
nsamps
;
eth
->
rx_count
++
;
return
(
bytes_received
);
}
}
}
//printf("size of third %d subtype %d frame %d subframe %d symbol %d \n", bytes_received, test_header->sub_type, ((test_header->frame_status)>>6)&0xffff, ((test_header->frame_status)>>22)&0x000f, ((test_header->frame_status)>>26)&0x000f) ;
int
trx_eth_write_udp_IF4p5
(
openair0_device
*
device
,
openair0_timestamp
timestamp
,
void
**
buff
,
int
nsamps
,
int
cc
,
int
flags
)
{
eth
->
rx_nsamps
=
nsamps
;
int
nblocks
=
nsamps
;
return
(
bytes_received
);
int
bytes_sent
=
0
;
}
eth_state_t
*
eth
=
(
eth_state_t
*
)
device
->
priv
;
int
trx_eth_write_udp_IF4p5
(
openair0_device
*
device
,
openair0_timestamp
timestamp
,
void
**
buff
,
int
nsamps
,
int
cc
,
int
flags
)
{
int
Mod_id
=
device
->
Mod_id
;
int
nblocks
=
nsamps
;
ssize_t
packet_size
;
int
bytes_sent
=
0
;
if
(
flags
==
IF4p5_PDLFFT
)
{
eth_state_t
*
eth
=
(
eth_state_t
*
)
device
->
priv
;
packet_size
=
UDP_IF4p5_PDLFFT_SIZE_BYTES
(
nblocks
);
int
Mod_id
=
device
->
Mod_id
;
}
else
if
(
flags
==
IF4p5_PULFFT
)
{
packet_size
=
UDP_IF4p5_PULFFT_SIZE_BYTES
(
nblocks
);
ssize_t
packet_size
;
}
else
if
(
flags
==
IF4p5_PRACH
)
{
packet_size
=
UDP_IF4p5_PRACH_SIZE_BYTES
;
if
(
flags
==
IF4p5_PDLFFT
)
{
}
else
{
packet_size
=
UDP_IF4p5_PDLFFT_SIZE_BYTES
(
nblocks
);
printf
(
"trx_eth_write_udp_IF4p5: unknown flags %d
\n
"
,
flags
);
}
else
if
(
flags
==
IF4p5_PULFFT
)
{
return
(
-
1
);
packet_size
=
UDP_IF4p5_PULFFT_SIZE_BYTES
(
nblocks
);
}
}
else
if
(
flags
==
IF4p5_PRACH
)
{
packet_size
=
UDP_IF4p5_PRACH_SIZE_BYTES
;
eth
->
tx_nsamps
=
nblocks
;
}
else
{
printf
(
"trx_eth_write_udp_IF4p5: unknown flags %d
\n
"
,
flags
);
bytes_sent
=
sendto
(
eth
->
sockfd
[
Mod_id
],
return
(
-
1
);
buff
[
0
],
}
packet_size
,
0
,
eth
->
tx_nsamps
=
nblocks
;
(
struct
sockaddr
*
)
&
dest_addr
[
Mod_id
],
addr_len
[
Mod_id
]);
bytes_sent
=
sendto
(
eth
->
sockfd
[
Mod_id
],
buff
[
0
],
if
(
bytes_sent
==
-
1
)
{
packet_size
,
eth
->
num_tx_errors
++
;
0
,
perror
(
"ETHERNET WRITE: "
);
(
struct
sockaddr
*
)
&
dest_addr
[
Mod_id
],
exit
(
-
1
);
addr_len
[
Mod_id
]);
}
else
{
eth
->
tx_actual_nsamps
=
bytes_sent
>>
1
;
if
(
bytes_sent
==
-
1
)
{
eth
->
tx_count
++
;
eth
->
num_tx_errors
++
;
}
perror
(
"ETHERNET WRITE: "
);
exit
(
-
1
);
return
(
bytes_sent
);
}
else
{
}
eth
->
tx_actual_nsamps
=
bytes_sent
>>
1
;
eth
->
tx_count
++
;
int
trx_eth_write_udp
(
openair0_device
*
device
,
openair0_timestamp
timestamp
,
void
**
buff
,
int
nsamps
,
int
cc
,
int
flags
)
{
}
int
bytes_sent
=
0
;
return
(
bytes_sent
);
eth_state_t
*
eth
=
(
eth_state_t
*
)
device
->
priv
;
}
int
Mod_id
=
device
->
Mod_id
;
int
sendto_flag
=
0
;
int
trx_eth_write_udp
(
openair0_device
*
device
,
openair0_timestamp
timestamp
,
void
**
buff
,
int
nsamps
,
int
cc
,
int
flags
)
{
int
i
=
0
;
//sendto_flag|=flags;
int
bytes_sent
=
0
;
eth
->
tx_nsamps
=
nsamps
;
eth_state_t
*
eth
=
(
eth_state_t
*
)
device
->
priv
;
int
Mod_id
=
device
->
Mod_id
;
for
(
i
=
0
;
i
<
cc
;
i
++
)
{
int
sendto_flag
=
0
;
/* buff[i] points to the position in tx buffer where the payload to be sent is
int
i
=
0
;
buff2 points to the position in tx buffer where the packet header will be placed */
//sendto_flag|=flags;
void
*
buff2
=
(
void
*
)(
buff
[
i
]
-
APP_HEADER_SIZE_BYTES
);
eth
->
tx_nsamps
=
nsamps
;
/* we don't want to ovewrite with the header info the previous tx buffer data so we store it*/
for
(
i
=
0
;
i
<
cc
;
i
++
)
{
int32_t
temp0
=
*
(
int32_t
*
)
buff2
;
/* buff[i] points to the position in tx buffer where the payload to be sent is
openair0_timestamp
temp1
=
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
));
buff2 points to the position in tx buffer where the packet header will be placed */
void
*
buff2
=
(
void
*
)(
buff
[
i
]
-
APP_HEADER_SIZE_BYTES
);
bytes_sent
=
0
;
/* we don't want to ovewrite with the header info the previous tx buffer data so we store it*/
/* constract application header */
int32_t
temp0
=
*
(
int32_t
*
)
buff2
;
// eth->pck_header.seq_num = pck_seq_num;
openair0_timestamp
temp1
=
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
));
//eth->pck_header.antenna_id = 1+(i<<1);
//eth->pck_header.timestamp = timestamp;
bytes_sent
=
0
;
*
(
uint16_t
*
)
buff2
=
pck_seq_num
;
*
(
uint16_t
*
)(
buff2
+
sizeof
(
uint16_t
))
=
1
+
(
i
<<
1
);
/* constract application header */
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
))
=
timestamp
;
// eth->pck_header.seq_num = pck_seq_num;
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME
(
VCD_SIGNAL_DUMPER_VARIABLES_TX_SEQ_NUM
,
pck_seq_num
);
//eth->pck_header.antenna_id = 1+(i<<1);
//eth->pck_header.timestamp = timestamp;
while
(
bytes_sent
<
UDP_PACKET_SIZE_BYTES
(
nsamps
))
{
*
(
uint16_t
*
)
buff2
=
pck_seq_num
;
#if DEBUG
*
(
uint16_t
*
)(
buff2
+
sizeof
(
uint16_t
))
=
1
+
(
i
<<
1
);
printf
(
"------- TX ------: buff2 current position=%d remaining_bytes=%d bytes_sent=%d
\n
"
,
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
))
=
timestamp
;
(
void
*
)(
buff2
+
bytes_sent
),
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME
(
VCD_SIGNAL_DUMPER_VARIABLES_TX_SEQ_NUM
,
pck_seq_num
);
UDP_PACKET_SIZE_BYTES
(
nsamps
)
-
bytes_sent
,
bytes_sent
);
while
(
bytes_sent
<
UDP_PACKET_SIZE_BYTES
(
nsamps
))
{
#endif
#if DEBUG
/* Send packet */
printf
(
"------- TX ------: buff2 current position=%d remaining_bytes=%d bytes_sent=%d
\n
"
,
bytes_sent
+=
sendto
(
eth
->
sockfd
[
Mod_id
],
(
void
*
)(
buff2
+
bytes_sent
),
buff2
,
UDP_PACKET_SIZE_BYTES
(
nsamps
)
-
bytes_sent
,
UDP_PACKET_SIZE_BYTES
(
nsamps
),
bytes_sent
);
sendto_flag
,
#endif
(
struct
sockaddr
*
)
&
dest_addr
[
Mod_id
],
/* Send packet */
addr_len
[
Mod_id
]);
bytes_sent
+=
sendto
(
eth
->
sockfd
[
Mod_id
],
buff2
,
if
(
bytes_sent
==
-
1
)
{
UDP_PACKET_SIZE_BYTES
(
nsamps
),
eth
->
num_tx_errors
++
;
sendto_flag
,
perror
(
"ETHERNET WRITE: "
);
(
struct
sockaddr
*
)
&
dest_addr
[
Mod_id
],
exit
(
-
1
);
addr_len
[
Mod_id
]);
}
else
{
#if DEBUG
if
(
bytes_sent
==
-
1
)
{
printf
(
"------- TX ------: nu=%d an_id=%d ts%d bytes_send=%d
\n
"
,
eth
->
num_tx_errors
++
;
*
(
int16_t
*
)
buff2
,
perror
(
"ETHERNET WRITE: "
);
*
(
int16_t
*
)(
buff2
+
sizeof
(
int16_t
)),
exit
(
-
1
);
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
)),
}
else
{
bytes_sent
);
#if DEBUG
dump_packet
((
device
->
host_type
==
BBU_HOST
)
?
"BBU"
:
"RRH"
,
buff2
,
UDP_PACKET_SIZE_BYTES
(
nsamps
),
TX_FLAG
);
printf
(
"------- TX ------: nu=%d an_id=%d ts%d bytes_send=%d
\n
"
,
#endif
*
(
int16_t
*
)
buff2
,
eth
->
tx_actual_nsamps
=
bytes_sent
>>
2
;
*
(
int16_t
*
)(
buff2
+
sizeof
(
int16_t
)),
eth
->
tx_count
++
;
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
)),
pck_seq_num
++
;
bytes_sent
);
if
(
pck_seq_num
>
MAX_PACKET_SEQ_NUM
(
nsamps
,
76800
)
)
pck_seq_num
=
1
;
dump_packet
((
device
->
host_type
==
BBU_HOST
)
?
"BBU"
:
"RRH"
,
buff2
,
UDP_PACKET_SIZE_BYTES
(
nsamps
),
TX_FLAG
);
}
#endif
}
eth
->
tx_actual_nsamps
=
bytes_sent
>>
2
;
/* tx buffer values restored */
eth
->
tx_count
++
;
*
(
int32_t
*
)
buff2
=
temp0
;
pck_seq_num
++
;
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
))
=
temp1
;
if
(
pck_seq_num
>
MAX_PACKET_SEQ_NUM
(
nsamps
,
device
->
openair0_cfg
->
samples_per_frame
)
)
pck_seq_num
=
1
;
}
}
}
return
(
bytes_sent
-
APP_HEADER_SIZE_BYTES
)
>>
2
;
/* tx buffer values restored */
}
*
(
int32_t
*
)
buff2
=
temp0
;
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
))
=
temp1
;
}
int
trx_eth_read_udp
(
openair0_device
*
device
,
openair0_timestamp
*
timestamp
,
void
**
buff
,
int
nsamps
,
int
cc
)
{
return
(
bytes_sent
-
APP_HEADER_SIZE_BYTES
)
>>
2
;
}
int
bytes_received
=
0
;
eth_state_t
*
eth
=
(
eth_state_t
*
)
device
->
priv
;
// openair0_timestamp prev_timestamp = -1;
int
Mod_id
=
device
->
Mod_id
;
int
trx_eth_read_udp
(
openair0_device
*
device
,
openair0_timestamp
*
timestamp
,
void
**
buff
,
int
nsamps
,
int
cc
)
{
int
rcvfrom_flag
=
0
;
int
block_cnt
=
0
;
int
bytes_received
=
0
;
int
again_cnt
=
0
;
eth_state_t
*
eth
=
(
eth_state_t
*
)
device
->
priv
;
int
i
=
0
;
// openair0_timestamp prev_timestamp = -1;
int
Mod_id
=
device
->
Mod_id
;
eth
->
rx_nsamps
=
nsamps
;
int
rcvfrom_flag
=
0
;
int
block_cnt
=
0
;
for
(
i
=
0
;
i
<
cc
;
i
++
)
{
int
again_cnt
=
0
;
/* buff[i] points to the position in rx buffer where the payload to be received will be placed
int
i
=
0
;
buff2 points to the position in rx buffer where the packet header will be placed */
void
*
buff2
=
(
void
*
)(
buff
[
i
]
-
APP_HEADER_SIZE_BYTES
);
eth
->
rx_nsamps
=
nsamps
;
/* we don't want to ovewrite with the header info the previous rx buffer data so we store it*/
for
(
i
=
0
;
i
<
cc
;
i
++
)
{
int32_t
temp0
=
*
(
int32_t
*
)
buff2
;
/* buff[i] points to the position in rx buffer where the payload to be received will be placed
openair0_timestamp
temp1
=
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
));
buff2 points to the position in rx buffer where the packet header will be placed */
void
*
buff2
=
(
void
*
)(
buff
[
i
]
-
APP_HEADER_SIZE_BYTES
);
bytes_received
=
0
;
block_cnt
=
0
;
/* we don't want to ovewrite with the header info the previous rx buffer data so we store it*/
int32_t
temp0
=
*
(
int32_t
*
)
buff2
;
openair0_timestamp
temp1
=
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
));
while
(
bytes_received
<
UDP_PACKET_SIZE_BYTES
(
nsamps
))
{
again:
bytes_received
=
0
;
#if DEBUG
block_cnt
=
0
;
printf
(
"------- RX------: buff2 current position=%d remaining_bytes=%d bytes_recv=%d
\n
"
,
(
void
*
)(
buff2
+
bytes_received
),
UDP_PACKET_SIZE_BYTES
(
nsamps
)
-
bytes_received
,
while
(
bytes_received
<
UDP_PACKET_SIZE_BYTES
(
nsamps
))
{
bytes_received
);
again:
#endif
#if DEBUG
bytes_received
+=
recvfrom
(
eth
->
sockfd
[
Mod_id
],
printf
(
"------- RX------: buff2 current position=%d remaining_bytes=%d bytes_recv=%d
\n
"
,
buff2
,
(
void
*
)(
buff2
+
bytes_received
),
UDP_PACKET_SIZE_BYTES
(
nsamps
),
UDP_PACKET_SIZE_BYTES
(
nsamps
)
-
bytes_received
,
rcvfrom_flag
,
bytes_received
);
(
struct
sockaddr
*
)
&
dest_addr
[
Mod_id
],
#endif
(
socklen_t
*
)
&
addr_len
[
Mod_id
]);
bytes_received
+=
recvfrom
(
eth
->
sockfd
[
Mod_id
],
buff2
,
if
(
bytes_received
==-
1
)
{
UDP_PACKET_SIZE_BYTES
(
nsamps
),
eth
->
num_rx_errors
++
;
rcvfrom_flag
,
if
(
errno
==
EAGAIN
)
{
(
struct
sockaddr
*
)
&
dest_addr
[
Mod_id
],
again_cnt
++
;
(
socklen_t
*
)
&
addr_len
[
Mod_id
]);
usleep
(
10
);
if
(
again_cnt
==
1000
)
{
if
(
bytes_received
==-
1
)
{
perror
(
"ETHERNET READ: "
);
eth
->
num_rx_errors
++
;
exit
(
-
1
);
if
(
errno
==
EAGAIN
)
{
}
else
{
again_cnt
++
;
printf
(
"AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN
\n
"
);
usleep
(
10
);
goto
again
;
if
(
again_cnt
==
1000
)
{
}
perror
(
"ETHERNET READ: "
);
}
else
if
(
errno
==
EWOULDBLOCK
)
{
exit
(
-
1
);
block_cnt
++
;
}
else
{
usleep
(
10
);
printf
(
"AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN AGAIN
\n
"
);
if
(
block_cnt
==
1000
)
{
goto
again
;
perror
(
"ETHERNET READ: "
);
}
exit
(
-
1
);
}
else
if
(
errno
==
EWOULDBLOCK
)
{
}
else
{
block_cnt
++
;
printf
(
"BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK
\n
"
);
usleep
(
10
);
goto
again
;
if
(
block_cnt
==
1000
)
{
}
perror
(
"ETHERNET READ: "
);
}
exit
(
-
1
);
}
else
{
}
else
{
#if DEBUG
printf
(
"BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK
\n
"
);
printf
(
"------- RX------: nu=%d an_id=%d ts%d bytes_recv=%d
\n
"
,
goto
again
;
*
(
int16_t
*
)
buff2
,
}
*
(
int16_t
*
)(
buff2
+
sizeof
(
int16_t
)),
}
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
)),
}
else
{
bytes_received
);
#if DEBUG
dump_packet
((
device
->
host_type
==
BBU_HOST
)
?
"BBU"
:
"RRH"
,
buff2
,
UDP_PACKET_SIZE_BYTES
(
nsamps
),
RX_FLAG
);
printf
(
"------- RX------: nu=%d an_id=%d ts%d bytes_recv=%d
\n
"
,
#endif
*
(
int16_t
*
)
buff2
,
*
(
int16_t
*
)(
buff2
+
sizeof
(
int16_t
)),
/* store the timestamp value from packet's header */
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
)),
*
timestamp
=
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
));
bytes_received
);
/* store the sequence number of the previous packet received */
dump_packet
((
device
->
host_type
==
BBU_HOST
)
?
"BBU"
:
"RRH"
,
buff2
,
UDP_PACKET_SIZE_BYTES
(
nsamps
),
RX_FLAG
);
if
(
pck_seq_num_cur
==
0
)
{
#endif
pck_seq_num_prev
=
*
(
uint16_t
*
)
buff2
;
}
else
{
/* store the timestamp value from packet's header */
pck_seq_num_prev
=
pck_seq_num_cur
;
*
timestamp
=
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
));
}
/* store the sequence number of the previous packet received */
/* get the packet sequence number from packet's header */
if
(
pck_seq_num_cur
==
0
)
{
pck_seq_num_cur
=
*
(
uint16_t
*
)
buff2
;
pck_seq_num_prev
=
*
(
uint16_t
*
)
buff2
;
//printf("cur=%d prev=%d buff=%d\n",pck_seq_num_cur,pck_seq_num_prev,*(uint16_t *)(buff2));
}
else
{
if
(
(
pck_seq_num_cur
!=
(
pck_seq_num_prev
+
1
)
)
&&
!
((
pck_seq_num_prev
==
75
)
&&
(
pck_seq_num_cur
==
1
))){
pck_seq_num_prev
=
pck_seq_num_cur
;
printf
(
"out of order packet received1! %d|%d|%d
\n
"
,
pck_seq_num_cur
,
pck_seq_num_prev
,(
int
)
*
timestamp
);
}
}
/* get the packet sequence number from packet's header */
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME
(
VCD_SIGNAL_DUMPER_VARIABLES_RX_SEQ_NUM
,
pck_seq_num_cur
);
pck_seq_num_cur
=
*
(
uint16_t
*
)
buff2
;
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME
(
VCD_SIGNAL_DUMPER_VARIABLES_RX_SEQ_NUM_PRV
,
pck_seq_num_prev
);
//printf("cur=%d prev=%d buff=%d\n",pck_seq_num_cur,pck_seq_num_prev,*(uint16_t *)(buff2));
eth
->
rx_actual_nsamps
=
bytes_received
>>
2
;
if
(
(
pck_seq_num_cur
!=
(
pck_seq_num_prev
+
1
)
)
&&
!
((
pck_seq_num_prev
==
MAX_PACKET_SEQ_NUM
(
nsamps
,
device
->
openair0_cfg
->
samples_per_frame
))
&&
(
pck_seq_num_cur
==
1
))
&&
!
((
pck_seq_num_prev
==
1
)
&&
(
pck_seq_num_cur
==
1
)))
{
eth
->
rx_count
++
;
printf
(
"out of order packet received1! %d|%d|%d
\n
"
,
pck_seq_num_cur
,
pck_seq_num_prev
,(
int
)
*
timestamp
);
}
}
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME
(
VCD_SIGNAL_DUMPER_VARIABLES_RX_SEQ_NUM
,
pck_seq_num_cur
);
}
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME
(
VCD_SIGNAL_DUMPER_VARIABLES_RX_SEQ_NUM_PRV
,
pck_seq_num_prev
);
/* tx buffer values restored */
eth
->
rx_actual_nsamps
=
bytes_received
>>
2
;
*
(
int32_t
*
)
buff2
=
temp0
;
eth
->
rx_count
++
;
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
))
=
temp1
;
}
}
}
return
(
bytes_received
-
APP_HEADER_SIZE_BYTES
)
>>
2
;
/* tx buffer values restored */
}
*
(
int32_t
*
)
buff2
=
temp0
;
*
(
openair0_timestamp
*
)(
buff2
+
sizeof
(
int32_t
))
=
temp1
;
}
return
(
bytes_received
-
APP_HEADER_SIZE_BYTES
)
>>
2
;
int
eth_set_dev_conf_udp
(
openair0_device
*
device
)
{
}
int
Mod_id
=
device
->
Mod_id
;
eth_state_t
*
eth
=
(
eth_state_t
*
)
device
->
priv
;
void
*
msg
;
ssize_t
msg_len
;
int
eth_set_dev_conf_udp
(
openair0_device
*
device
)
{
int
Mod_id
=
device
->
Mod_id
;
/* a BBU client sents to RRH a set of configuration parameters (openair0_config_t)
eth_state_t
*
eth
=
(
eth_state_t
*
)
device
->
priv
;
so that RF front end is configured appropriately and
void
*
msg
;
frame/packet size etc. can be set */
ssize_t
msg_len
;
msg
=
malloc
(
sizeof
(
openair0_config_t
));
msg_len
=
sizeof
(
openair0_config_t
);
/* a BBU client sents to RRH a set of configuration parameters (openair0_config_t)
memcpy
(
msg
,(
void
*
)
device
->
openair0_cfg
,
msg_len
);
so that RF front end is configured appropriately and
frame/packet size etc. can be set */
if
(
sendto
(
eth
->
sockfd
[
Mod_id
],
msg
,
msg_len
,
0
,(
struct
sockaddr
*
)
&
dest_addr
[
Mod_id
],
addr_len
[
Mod_id
])
==-
1
)
{
perror
(
"ETHERNET: "
);
msg
=
malloc
(
sizeof
(
openair0_config_t
));
exit
(
0
);
msg_len
=
sizeof
(
openair0_config_t
);
}
memcpy
(
msg
,(
void
*
)
device
->
openair0_cfg
,
msg_len
);
return
0
;
if
(
sendto
(
eth
->
sockfd
[
Mod_id
],
msg
,
msg_len
,
0
,(
struct
sockaddr
*
)
&
dest_addr
[
Mod_id
],
addr_len
[
Mod_id
])
==-
1
)
{
}
perror
(
"ETHERNET: "
);
exit
(
0
);
int
eth_get_dev_conf_udp
(
openair0_device
*
device
)
{
}
eth_state_t
*
eth
=
(
eth_state_t
*
)
device
->
priv
;
return
0
;
int
Mod_id
=
device
->
Mod_id
;
}
char
str1
[
INET_ADDRSTRLEN
],
str
[
INET_ADDRSTRLEN
];
void
*
msg
;
int
eth_get_dev_conf_udp
(
openair0_device
*
device
)
{
ssize_t
msg_len
;
eth_state_t
*
eth
=
(
eth_state_t
*
)
device
->
priv
;
msg
=
malloc
(
sizeof
(
openair0_config_t
));
int
Mod_id
=
device
->
Mod_id
;
msg_len
=
sizeof
(
openair0_config_t
);
char
str1
[
INET_ADDRSTRLEN
],
str
[
INET_ADDRSTRLEN
];
void
*
msg
;
inet_ntop
(
AF_INET
,
&
(
local_addr
[
Mod_id
].
sin_addr
),
str
,
INET_ADDRSTRLEN
);
ssize_t
msg_len
;
inet_ntop
(
AF_INET
,
&
(
dest_addr
[
Mod_id
].
sin_addr
),
str1
,
INET_ADDRSTRLEN
);
msg
=
malloc
(
sizeof
(
openair0_config_t
));
/* RRH receives from BBU openair0_config_t */
msg_len
=
sizeof
(
openair0_config_t
);
if
(
recvfrom
(
eth
->
sockfd
[
Mod_id
],
msg
,
inet_ntop
(
AF_INET
,
&
(
local_addr
[
Mod_id
].
sin_addr
),
str
,
INET_ADDRSTRLEN
);
msg_len
,
inet_ntop
(
AF_INET
,
&
(
dest_addr
[
Mod_id
].
sin_addr
),
str1
,
INET_ADDRSTRLEN
);
0
,
(
struct
sockaddr
*
)
&
dest_addr
[
Mod_id
],
/* RRH receives from BBU openair0_config_t */
(
socklen_t
*
)
&
addr_len
[
Mod_id
])
==-
1
)
{
if
(
recvfrom
(
eth
->
sockfd
[
Mod_id
],
perror
(
"ETHERNET: "
);
msg
,
exit
(
0
);
msg_len
,
}
0
,
device
->
openair0_cfg
=
(
openair0_config_t
*
)
msg
;
(
struct
sockaddr
*
)
&
dest_addr
[
Mod_id
],
(
socklen_t
*
)
&
addr_len
[
Mod_id
])
==-
1
)
{
/* get remote ip address and port */
perror
(
"ETHERNET: "
);
/* inet_ntop(AF_INET, &(dest_addr[Mod_id].sin_addr), str1, INET_ADDRSTRLEN); */
exit
(
0
);
/* device->openair0_cfg->remote_port =ntohs(dest_addr[Mod_id].sin_port); */
}
/* device->openair0_cfg->remote_addr =str1; */
device
->
openair0_cfg
=
(
openair0_config_t
*
)
msg
;
/* /\* restore local ip address and port *\/ */
/* get remote ip address and port */
/* inet_ntop(AF_INET, &(local_addr[Mod_id].sin_addr), str, INET_ADDRSTRLEN); */
/* inet_ntop(AF_INET, &(dest_addr[Mod_id].sin_addr), str1, INET_ADDRSTRLEN); */
/* device->openair0_cfg->my_port =ntohs(local_addr[Mod_id].sin_port); */
/* device->openair0_cfg->remote_port =ntohs(dest_addr[Mod_id].sin_port); */
/* device->openair0_cfg->my_addr =str; */
/* device->openair0_cfg->remote_addr =str1; */
/* printf("[RRH] mod_%d socket %d connected to BBU %s:%d %s:%d\n", Mod_id, eth->sockfd[Mod_id],str1, device->openair0_cfg->remote_port, str, device->openair0_cfg->my_port); */
/* /\* restore local ip address and port *\/ */
return
0
;
/* inet_ntop(AF_INET, &(local_addr[Mod_id].sin_addr), str, INET_ADDRSTRLEN); */
}
/* device->openair0_cfg->my_port =ntohs(local_addr[Mod_id].sin_port); */
/* device->openair0_cfg->my_addr =str; */
/* printf("[RRH] mod_%d socket %d connected to BBU %s:%d %s:%d\n", Mod_id, eth->sockfd[Mod_id],str1, device->openair0_cfg->remote_port, str, device->openair0_cfg->my_port); */
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment