Forum Discussion
Altera_Forum
Honored Contributor
16 years agoHow do Nios-II handle IP address change during the TCP/IP connection?
Dear all,
I have problem with changing IP address in the FPGA board. Here is my case, let say I have a FPGA board which is connected to PC. The PC sends a command to the FPGA that asks the FPGA to change its IP address to a new given IP address. Here is my idea to handle this task :- After receiving IP changes command from PC, both FPGA and PC terminate their TCP/IP connection by close their socket.
- The FPGA does the IP changes mechanism
- Both FPGA and PC initiate a new TCP/IP connection like usual
- The FPGA sends acknowledgement to the PC to tell that it already changes its IP address successfully.
- Terminate the previous TCP/IP connection (close the exist socket)
- Assign new IP address to the FPGA (I have made a new function called 'change_ip' which is basically same as get_ip_addr function provided by altera)
- Initiate new TCP/IP connection (create, bind, listen socket)
: See STDERR for expanded diagnosis translation.
: Bind failed
: ERRNO: :
: See STDERR (FAULT_LEVEL is SYSTEM).
: FAULT_LEVEL is SYSTEM.
: FATAL Error, Restart required.
: Locking scheduler - endless loop. I also tried to kill the previous "inet main" and "clock tick" tasks, but in the end it also ends up with the same error message. Anybody know how is the correct procedure to change FPGA's IP address? :confused: :confused: Thanks for any comments or suggestions!27 Replies
- Altera_Forum
Honored Contributor
Can you be a bit more specific?
What are you trying to do? - Altera_Forum
Honored Contributor
Ah sorry, I didn't tell you before. What I'm trying to do is I want to change my Nios IP address by sending a command from PC.
So here is the step-by-step process that happen in my current system :- At first Nios obtains its IP address via DHCP
- Nios acts as a server and provides a TCP/IP connection. It does these TCP/IP connection initiation functions : creating socket, binding, listening, and selecting socket
- PC builds TCP/IP connection to Nios
- After the TCP/IP connection has been established, PC sends a command to Nios (via TCP/IP) that tells Nios to change its IP address. In this step, the new IP address that will be assigned to the Nios is determined by PC (the new IP address is also sent with the command).
- After sending the command, PC will close the TCP/IP connection (since Nios will use the new IP address, the previous TCP/IP connection will be broken)
- Nios change its IP address (using 'change_ip' function, static method)
- Nios repeat step no.2
- PC repeat step no.3 (of course, PC will call Nios using its new IP address)
- Nios sends a official notification to PC that it has changed its IP address correctly.
- Altera_Forum
Honored Contributor
Yes, I get the idea.
I have just been using the webserver example, and there is no need to re-do the socket_create/bind/listen stuff. I just issue change_ip() and the webserver is responding at the new address. I'm not sure whether the example takes care of it, but I would be surprised if it does. Where is your problem? Are you getting an error in Step 7? Are you getting no connection in Step 8? - Altera_Forum
Honored Contributor
Update :
When PC sends a command to Nios that tells Nios to renew its DHCP IP address, Nios can re-initialize the new TCP/IP connection correctly. Hmm.... I'm wondering what's wrong with my static ip address assignment case. - Altera_Forum
Honored Contributor
I am failed at step 7. Since the step 7 is failed of course step 8 is also failed (because PC couldn't find the available socket)
Wow really?? are you sure you don't need to re-do the TCP/IP establishment? How can the previous TCP/IP connection is not broken? I've tried also without re-initialization of TCP/IP connection, but it was error on step 8. But the strange thing is I can ping the Nios with its new IP address. - Altera_Forum
Honored Contributor
I assume, server sockets are indepentent of the given IP address.
Once a client connects, a new socket is created for this connection. This new socket might be bound to the ip address. I have no idea why your server should not be reachable, if ping is working. Maybe you can compare the ping code to yours? - Altera_Forum
Honored Contributor
Hi all,
I want to inform you that the bind-socket problem in my design can be overcome by connecting to the Nios via different port. It seems that the previous port is still being used (somehow..I don't know:confused:) So now I face another problem. I have closed my previous socket (using close() function), changed Nios' IP address with the new IP address, re-initialize TCP/IP connection (create socket, bind, listen) correctly / without error. But when I tried to access the Nios (which has been assigned with the new ip address) from my PC, my PC always couldn't connect to the Nios :confused:. It looked like that my PC couldn't find the Nios' new socket. :confused: Meanwhile, the Nios was ready to accept any new connection. The Nios IP address also could be ping from my PC. So do anyone know how to solve this problem?? :( I'm thinking that the previous socket wasn't closed completely. Does anyone know how to completely destroy the old socket? Thanks all! Hopefully anyone of you can help me to figure out my problem. - Altera_Forum
Honored Contributor
@mcr42
Hi, I want to ask you some questions. You said that after you changed the Nios' IP address, you didn't need to close the previous connection or re-initialize the TCP/IP connection. When your Nios changed its IP address, was it still connected to any client or not :confused:? I mean, has The Nios accepted a TCP/IP connection request from any client before it changed its IP address? In my case, before the Nios changed its IP address, it was still connected to a client. And my problem is in maintaining or rebuilding a new TCP/IP connection to the same client. Would you share a piece of your code? I'm still curious how you can maintain the TCP/IP connection despite of Nios IP changes. If you mind to put it in this public thread, you may send it by private message to me. Thank you. p.s. I really appreciate if there are anyone have suggestion to solve my problem. :( - Altera_Forum
Honored Contributor
Hello fightingdreamer, i would like a piece of your code that you used to transfer from fifo->pio->sdram, if you could.. (send me a private msg or e-mail me at [email protected] :D)
Thanks - Altera_Forum
Honored Contributor
I did not write any code concerning connections.
I was just using the web server example, which I checked from the browser on my development machine. The NIOS web server responded on one IP address, the IP address was changed, and the NIOS responded on the new IP address. But HTTP is not a protocoll where connections are kept open for long. So I have not changed the IP during an active connection. But, I'd assume the TPC stack drops all packets that don't match the IP address (as it probably should). The server however starts responding as soon as the new IP address is in place.