FPGA üzerinde MAC/IP/UDP protokolünün gerçeklenmesi
Implementation of MAC/IP/UDP protocol on FPGA
Yazar: SERVET AYOK
Danışman: DOÇ. DR. MÜŞTAK ERHAN YALÇIN
İstanbul Teknik Üniversitesi / Fen Bilimleri Enstitüsü / Elektronik ve Haberleşme Mühendisliği Ana Bilim Dalı / Elektronik Mühendisliği Bilim Dalı
Derece: Yüksek Lisans, 2013
Konu: Elektrik ve Elektronik Mühendisliği = Electrical and Electronics Engineering
Dizin: FPGA = FPGA ; TCP/IP = TCP/IP ; İletişim ağları = Communication networks

Özet:
Bilgisayarlar çok güçlü ve yetenekli cihazlar olmalarına rağmen, birbirleri ile haberleşemediklerinde yetenekleri önemli ölçüde sınırlandırılmış olur. Veri ve kaynak paylaşımı amacı ile bilgisayarlar arasında bir ağ kurulduğunda, kullanıcıya daha etkin ve güçlü bir sistem sağlamaktadırlar. Ağ bir bina içindeki bilgisayarlar arasında kurulabileceği gibi, kıtalar arası birçok bilgisayar arasında da kurulabilmektedir.
Bilgisayar ağlarının ilk yıllarında firmalar bilgisayarları haberleştirebilmek için kendi donanın ve yazılımlarını satıyorlardı. Bu sistemler kendi içinde uyumlu çalışmasına rağmen farklı ağ sistemleri donanım ve yazılım farklılıklarından dolayı düzgün haberleşemiyordu. Bu durum ağ tabanlı yazılım geliştirmek isteyen kişiler için de zorluk yaratıyordu. Bu amaçla 1970?lerin sonlarında ve 1980?lerin başlarında ISO?nun TC 97 (Technical Committee 97), Enformasyon İşleme?si tarafından Açık Sistem Bağlantısı OSI modeli (Open System Interconnect) geliştirilmeye başlanmış,  son OSI modeli 1984?te çıkartılmıştır.
Uygulamaya özel tümdevre tasarlamanın maliyet, süre ve zorluk gibi dezavantajları olduğundan, tasarımcılar yeniden konfigüre edilebilir yapılara ihtiyaç duymuşlardır. Önceleri PLA, PAL gibi basit PLD?ler kullanılsa da kapasite, hız ve yetenek ihtiyaçları arttıkça, CPLD ve sonra FPGA gibi karmaşık yapılar geliştirilmiştir. CPLD?ler ayrık halde bulunan PLD?lerin performansını iyileştirmek, kapladığı alanı azaltmak ve güvenilirliği arttırmak amacı ile bir araya getirilmesi ile oluşturulmuştur. 
Daha sonra CPLD?lerden daha gelişmiş yapıya sahip olan FPGA?lar geliştirilmiştir. Tasarımcılar için esnek bir platform sunan FPGA?lar günümüzde çok popüler hale gelmiştir. FPGA?ların en önemli uygulama alanları arasında savunma ve uzay sanayi, sayısal işaret ve görüntü işleme, telekomünikasyon, tıbbi görüntüleme ve otomotiv sanayi sayılabilir. 
Bu tez çalışmasında, FPGA?lerin ethernet arayüzünü destekleyen cihazlarla haberleşebilmesi amacı ile ethernet MAC, IP ve UDP katmanlarının VHDL dili ile gerçeklenmesi yapılmıştır. Bu amaçla, Avnet firmasının tasarladığı, Xilinx firmasının Spartan 6 ailesinden XC6SLX9 tipi FPGA içeren LX9 Microboard kullanılmıştır.
Öncelikle MAC, IP ve UDP katmanları için, hem gönderim hem alım işlemini sağlayan VHDL modülleri yazılmıştır. Ücretsiz olan Xilinx ISE 14.1 Webpack sürümü üzerinde yazılan VHDL kodlarının, Xilinx ISIM simülatör yazılımı ile davranışsal benzetimi yapılmıştır. Son olarak Xilinx ISE 14.1 ile proje gerçeklenmiş, Xilinx Impact kullanılarak FPGA?ya gömülmüştür. Ayrıca gerçek devre ile test edebilmek amacıyla Uart modülü entegre edilmiştir. Böylece test için bilgisayardan gönderilen ethernet paketleri Uart üzerinden alınabilmiş, Uart üzerinden gönderilen veriler de bilgisayarda ethernet üzerinden alınabilmiştir. 
Sistemi test edebilmek amacı ile Ethernet arayüzünden ve Uart arayüzünden 20ms aralıklarla istenilen sayıda paket atıp, gelen paketler ile karşılaştıran bir C# uygulaması yazılmıştır. Yapılan testlerde 10000 paket atılmış ve hiç paket kaybı yaşanmamıştır.
Örnek bir uygulama olması açısında, ev güvenlik uygulaması geliştirilmiştir. Bu amaçla bir adet hareket sensörü ve bir adet darbe sensörü FPGA kartına bir ara kart ile bağlanmış, sensörlerden gelen alarmları kontrol edip bilgisayara uygun UDP paketleri atan modül yazılmıştır. FPGA kartı ile haberleşip sensörlerin durumlarını gösteren bir C# uygulaması yazılmıştır.
Tez çalışmasında öncelikle, OSI katman yapısı ve ağ topolojileri hakkında bilgi verilmiştir. Daha sonra sırası ile ethernet MAC, IP ve UDP katmanları hakkında bilgi verilmiş ve paket yapıları detaylı bir şekilde anlatılmıştır. Arkasından yeniden programlanabilir yapılar ve FPGA hakkında detaylı bilgi verilmiştir. Son olarak bütün VHDL modülleri tek tek açıklanmış, basitleştirilmiş durum diyagramları verilmiştir.

Abstract:
Although the computers are powerful and talented devices, their capabilities are limited without communication with each other. A more powerful system is provided to the user when a network is established between computers to share data and resource.
In the first years of computer network, companies were developing and selling their custom hardware and software. Although those systems were able to work well, they were not compatible with network systems from different companies. For this purpose, Technical Committee 97 from ISO started to develop Open System Interconnect and released the latest version in 1984.
In order to divide the communication into layers, some rules has to be followed. First, every layers must have a well-defined function. While defining functions for layers, international communication standards must be considered. Layers borders must be defined such that communication between layers must be minimum. Number of layers must be optimum such that a function must not contain two layers and system must not be cumbersome. 
By dividing the communication into layers, designers may specialize on different layers. Thus different designers may work on different layers of the system at the same time. This can also simplify error detection and solution.
7 layers of OSI are physical layer, data link layer, network layer, transport layer, session layer, presentation layer and application layer. Ethernet in on data link layer, IP is on network layer and UDP is on transport layer. Physical layer of Ethernet communication is provided by a chip called Ethernet PHY.
Ethernet was developed and tested by Dr. Robert Metcalfe at Palo Alto research center in 1970. He could make a communication between Alto computers and laser printers with 2.94 Mbps using a coaxial cable. Name of ethernet was originated from ether which is believed to fill the universe. Ethernet was used in Xerox until 1970 and was released in 1980 officially. Xerox, DEC and Intel published DIX Standart that has 10Mbps speed over coaxial cable.
While developing Ethernet, three problems had to be solved such as how the data is sent over cable, how the sender and receiver are detected and which node uses the cable for half duplex lines. Data is sent in small packets so a computers does not occupy the line for huge data transfer and retransmission can be done for each packet in case of an error. Each computer has a 48-bit unique MAC address and an Ethernet packet contains both sender MAC address and receiver MAC address. Also carrier sense multiple access with collision detection method was developed to detect the node, which will use the line.
Internet protocol is on the third layer of the OSI architecture. Purpose of the IP layer is to provide a connectionless communication between two computers through several IP networks by using only IP addresses. IP is a connectionless protocol, it does not guarantee delivery of the packets. Thus it is possible that IP packets do not arrive, arrive twice, corrupt or arrive in different orders. TCP, which is on the forth layer of OSI, guarantees the delivery of the packet.
Every computer on internet has a unique 32-bit IP address for IPv4. Since 4294967296 IP addresses for IPv4 are not sufficient nowadays, IPv6 has been developed which has 128-bit IP address.
When a computer wishes to send data over IP, it needs to know the IP and MAC addresses of the destination computer. In a case such that IP address is known but MAC address is not, computer sends an ARP request, and the receiver computer replies the ARP request with its own MAC address inside. Therefore, sender computer learns the MAC address and stores it to ARP table.
UDP is on the forth layer of OSI architecture. Purpose of UDP layer is to provide a connectionless communication between two software threads on a computer. UDP is a connectionless protocol, it does not guarantee delivery of the packets. UDP contains error detection but does not have error correction mechanism like TCP. The reasons why UDP is used instead of TCP are small header size, fast processing of packet and being appropriate for time critical application like voice over IP. 
Although there are analog implementations, today computers, communication systems, signal and image processing systems are implemented as digital. First digital electronics applications were developed after the invention of magnetically controllable relays but digital computation age started after the invention of vacuum tubes.
First computer ENIAC, which used vacuum tubes, was designed in 1945 to calculate the trajectory of field gun of the American army. Since power consumption was too high, there were thermal cooling problems. It was 25m long, 3m tall and had 18000 tubes. After the invention of bipolar transistors at Bell laboratories in 1947, transistors replaced the vacuum tubes and digital and analog designs had a breakthrough.      
Due to the cost, time and difficulty disadvantages of ASIC design, designers needed reconfigurable structures. Reconfigurable devices include reconfigurable blocks and configurable interconnects. In the first years of reconfigurable devices, simple structures like PLA and PAL were used, however, as the need for capacity, speed and capabilities increased, complex structures like CPLD and FPGA were developed. CPLDs are formed by combining discrete PLDs to improve the performance, reduce the total area and improve the reliability. 
Later FPGAs, which have more complex structure, were developed. FPGAs are very popular today due to serving a flexible platform for designers. Codes written with VHDL or Verilog languages are converted to digital circuit by special software. FPGAs use different technologies such as anti-fuse, eeprom and sram. Anti-fuse technology allows programming only once. Eeprom technology allows programming multiple times but programming is slow and due to eeprom structure, it is difficult to manufacture. Sram structure is fast and easy to manufacture but it requires external non-volatile memory. 
Basic building blocks of FPGA are configurable logic blocks, configurable interconnects and input output blocks. FPGAs may also include DSP blocks, digital clock managers, memory, Ethernet MAC, PCI controller and embedded microprocessors. Most important application fields of FPGAs are defense and space industry, digital signal and image processing, telecommunication, medical imaging and automotive industry. 
In this thesis, ethernet MAC, IP and UDP modules are implemented in VHDL for FPGAs to communicate with devices supporting ethernet interface. For this purpose LX9 Microboard, which is designed by Avnet containing Spartan 6 family XC6SLX9 FPGA, is used.
Firstly, VHDL modules of MAC, IP and UDP are implemented for both transmit and receive. VHDL modules, which are written on Xilinx ISE 14.1 Webpack free version, are simulated on Xilinx ISIM  Simulator tool. Finally project is implemented on Xilinx ISE 14.1 and downloaded to FPGA by Xilinx Impact. An Uart module is integrated to project for test purposes. Ethernet packets sent from computer can be received from uart port on computer, uart packets sent from computer can be received from ethernet port on computer. Docklight terminal software is used to send and receive the uart packets. Colasoft Packet Builder software is used to generate UDP packets. Wireshark software is used to observe the UDP packets received by the computer.
In order to test the system, a C# application is developed which sends Ethernet and uart packets every 20ms. Application receives and compares the packets then increments the counter of each packet type. For test, 10000 packets were sent and packet loss was not seen.
Home security application is developed to show the possible application areas of the core. A printed circuit board was designed which interfaces a PIR sensor and a vibration sensor with FPGA board. A VHDL module that sends packets to computer in case of an alarm replaced the uart module. A C# application was developed which communicates with the FPGA board and shows the status and time of the individual sensors.
Finally, resource the design uses and timing values are given. Core is compared with other works in the literature in terms of resource and timing performance. Then future works that can be done are given.
In the thesis, firstly information about OSI model and network topologies are supplied. Later, information about ethernet MAC, IP and UDP is supplied and detailed packet structures are deeply analyzed. Information about reconfigurable structures and FPGA are supplied. Each VHDL module is explained individually and simplified state diagrams are given. Functional and performance test procedures are explained. An example application is shown and comparison with other works is done.