OpenCores
URL https://opencores.org/ocsvn/fpga-cf/fpga-cf/trunk

Subversion Repositories fpga-cf

[/] [fpga-cf/] [trunk/] [java/] [src/] [edu/] [byu/] [cc/] [plieber/] [fpgaenet/] [fcp/] [FCPReceiveThread.java] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
/**
2
 *
3
 */
4
package edu.byu.cc.plieber.fpgaenet.fcp;
5
 
6
import java.io.IOException;
7
import java.net.*;
8
 
9
/**
10
 * @author plieber
11
 *
12
 */
13
class FCPReceiveThread extends Thread {
14
        private FCPProtocol protocol;
15
        protected boolean done;
16
 
17
        public FCPReceiveThread(FCPProtocol protocol) {
18
                this.protocol = protocol;
19
        }
20
 
21
        @Override
22
        public void run() {
23
                while (true) {
24
                        try {
25
                                if (done == true)
26
                                        return;
27
                                byte[] buf = new byte[1280];
28
 
29
                                // receive next packet
30
                                DatagramPacket packet = new DatagramPacket(buf, buf.length);
31
                                while (true) {
32
                                        try {
33
                                                protocol.socket.receive(packet);
34
                                                //System.out.println("DatagramPacket: " + packet.toString());
35
                                                break;
36
                                        } catch (SocketTimeoutException e) {
37
                                                if (done == true)
38
                                                        return;
39
                                                else
40
                                                        continue;
41
                                        }
42
                                }
43
                                //System.out.println("Got one!");
44
                                FCPPacket fcppacket = new FCPPacket(packet);
45
                                //System.out.println(fcppacket.toString());
46
                                //System.out.flush();
47
 
48
                                if (protocol.connected) {
49
                                        // parse
50
                                        if (protocol.recWindow == 1) {
51
                                                if (fcppacket.command == 0
52
                                                                && fcppacket.seq == protocol.rec_cur) {
53
                                                        protocol
54
                                                                        .sendAck(packet.getAddress(), fcppacket.seq);
55
                                                        protocol.rec_cur++;
56
                                                        protocol.processPacket(fcppacket);
57
                                                } else if (fcppacket.command == 5) {
58
                                                        protocol.snd_last_ack = fcppacket.seq;
59
                                                        protocol.packetOutbox.remove(fcppacket.seq);
60
                                                        protocol.processPacket(fcppacket);
61
                                                } else if (fcppacket.command == 1) {
62
                                                        protocol.snd_last_ack = fcppacket.seq;
63
                                                        protocol.packetOutbox.remove(fcppacket.seq);
64
                                                } else if (fcppacket.command == 3) {
65
                                                        protocol.resetSW();
66
                                                        protocol.connectedAddress = InetAddress
67
                                                                        .getByName(packet.getAddress().getHostAddress());
68
                                                        protocol.connectedPort = packet.getPort();
69
                                                        protocol.connected = true;
70
                                                        System.out.println("Reset Connection");
71
                                                }
72
                                        } else
73
                                                throw new IOException(
74
                                                                "Receive window greater than 1 not supported");
75
                                } else {
76
                                        if (fcppacket.command == 2) {
77
                                                protocol.resetSW();
78
                                                protocol.connectedAddress = packet.getAddress();
79
                                                protocol.connectedPort = packet.getPort();
80
                                                protocol.connected = true;
81
                                                // This is where we would set the ConARP table
82
                                                System.out.println("Received Connection Req");
83
                                                System.out.println("Connected to: "
84
                                                                + protocol.connectedAddress.getHostAddress()
85
                                                                + " on port " + protocol.connectedPort);
86
                                                protocol.sendConAck();
87
                                        } else if (fcppacket.command == 3 || fcppacket.command == 1) {
88
                                                protocol.resetSW();
89
                                                protocol.connectedAddress = InetAddress
90
                                                                .getByName(packet.getAddress().getHostAddress());
91
                                                protocol.connectedPort = packet.getPort();
92
                                                protocol.connected = true;
93
                                                System.out.println("Received Connection Ack");
94
                                                System.out.println("Connected to: "
95
                                                                + protocol.connectedAddress.getHostAddress()
96
                                                                + " on port " + protocol.connectedPort);
97
                                        }
98
                                }
99
                        } catch (IOException e) {
100
                                e.printStackTrace();
101
                                return;
102
                        }
103
                }
104
        }
105
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.