Ethernet etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Ethernet etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

14 Eylül 2020 Pazartesi

Ethernet ve Kablolama

Giriş
Açıklaması şöyle
Ethernet is a set of standards (IEEE 802.3) which covers transmitting data via coaxial cable, twisted pairs as well as fibre.

802.3a - 10Base2 - coax
802.3i - 10Base-T - twisted pairs
802.3u - 100Base-Tx, or more colloquially 100Base-T - twisted pairs
802.3z - 1000Base-X - fibre
802.3ab - 1000Base-T - twisted pairs
10Base5
10Base5 ve 10Base2 coax kablolar. İkisinin arasındaki en önemli farkın açıklaması şöyle
10BASE5 had a maximum length of 500 meters. 10BASE2 reduced the maximum length to 185 meters, but where that much lower length was sufficient this was a good trade-off for having cable that was cheaper and easier to handle. In part this was due to 10BASE2 cable being thinner, but the really big advantage was that, while the 10BASE5 medium was a single cable long cable, the 10BASE2 medium could be constructed from many segments of short cable, joined together with "T" connectors at each station. This allowed much easier re-routing of the transmission medium to include, e.g., a new room off to the side of the existing run.
CAT-3, CAT5E, CAT-6, CAT-7 kablo çeşitleri var. Tüm kablolar aslında 4 çift Unshielded Twisted Pair (UTP) 'den oluşuyor. 10MB ethernet için CAT-3 ve üstü gerekir

Topraklama
Ethernet kablosunda ground (topraklama) kablosu gerekmez. Ground gerekmemesiniz sebebi Unshielded Twisted Pair'in differential signaling kullanması. Açıklaması şöyle.
Twisted pair uses differential signaling - in a pair, one wire is always the negative/complimentary signal of the other. In the simplest example, Transmit+ > Transmit- means 1 and Transmit+ < Transmit- means 0. Put in another way, each wire is a reference for the other. There is no reference to ground.

For 10BASE-T and 100BASE-TX there's a dedicated pair each for transmitting data and receiving data.
CAT-3
CAT-3 ve CAT-6 yan yana kullanılabilir. Açıklaması şöyle
...as each cable has twisted pairs to prevent EMF interference, with each twisted pair's twist being a different length than the others.
CAT-5
100 MB ethernet için CAT5E ve üstü gerekir. Eski 8 pinli telefon kablosunu RJ55 ile sonlandırarak CAT5 elde edilebilir. Kablolar şöyle

Cross Cable
Eğer hub kullanmayacaksak Ethernet kablosunu çapraz bağlamaya (crossover cable) gerek yoktur. Ethernet kartları artık Auto MDI-X teknolojisi ile çapraz çalışması gerektiğini anlayabiliyor.

RJ-45
RJ-45 sadece duvardaki giriş yeri. Ethernet standardı ile alakası yok. Bazen telefon için bile kullanılıyor.

10Base2 - İlkel Ethernet
Coax kablo kullanırdı. Açıklaması şöyle.
Early Ethernet did use coax cabling.

Modern Ethernet uses twisted pairs to eliminate EMI, but only 10 and 100 Mbit/s have dedicated pairs for transmit and receive - Gbit upwards uses all pairs in both directions simultaneously.
10BaseT Ethernet - Unshielded Twisted Pair (UTP)
Açıklaması şöyle.
10BaseT and 10BaseFx are standards of connectivity for Ethernet.

10BaseT defines the use of UTP cabling for Ethernet, that includes cable features, male (in cable) and female (in wall boxes) connectors, max distances, etc.
10BaseFx Ethernet - Fiber
Açıklaması şöyle
10BaseFx defines the use of fiber optics for Ethernet, including type of fiber, max distances, connectors (in cable and in wall boxes), etc.
Açıklaması şöyle
10BASE-FX is no official IEEE 802.3 standard - various, non-compatible versions may exist. The 10 Mbit/s standard PHY is (was) 10BASE-FL. Fast Ethernet has 100BASE-FX as common standard.
10 G Ethernet
Saniyede 10 milyar bit olarak düşünürsek inanılmaz bir rakam. Verinin nasıl gönderildiğini burada.

Auto Negotiation
Tüm ethernet kartları Auto Negotiation özelliğini kullanırsa daha iyi. Açıklaması şöyle
The classic reason for a duplex mismatch is forcing one side to full duplex while keeping the other side set to Auto Negotiation. Failing AN, that side falls back to half duplex, creating the mismatch.
Ethernet Sürücüsü Kablonun Çekildiğini Nasıl Algılar?
Açıklaması şöyle
-The original coax Ethernet did not really have link state detection (some PHYs had a mechanism for detecting termination during transmission but it only worked when the device was actually trying to transmit something)

-10BASE-T uses "link state pulses" which are sent when the line is idle to monitor link status.
Twisted pair auto-negotiation uses "Fast link pulse bursts" to both determine the state of the link and to exchange auto-negotiation information. Once a link type has been negotiated link type specific mechanisms are used to monitor link status.

-Faster Ethernet standards generally transmit idle codes continuously.
Benzer bir açıklama şöyle
In the original 100BASE-TX, nothing is transmitted in the Inter Packet Gap (IPG) period. Energy-efficient Ethernet adds low-power idle (LPI) mode which sends idle symbols generated by the Packet Coding Sublayer (PCS).
1 GB Ethernet Aynı Kablo İle Nasıl Daha Çok Veri Gönderir?
100 MB ethernet tek bir kablo çiftini kullanır ve sadece 1 ve 0 değerini taşıyan voltajı 100 MHz'de gönderebilir.

1 GB Ethernet ise tüm kablo çiftlerini kullanır ve 00,01,10,11 değerlerini taşıyan voltajı 125 MHz'de gönderebilir. Dolayısıyla daha çok veri taşıyabilir. Açıklaması şöyle.
Most commonly, 1000BASE-T - the common gigabit-over-copper variant - splits the encoded data stream into four lanes and transmits each separately on one of the four twisted pairs in a Cat-5 cable. All copper variants from gigabit upwards use these four lanes.


6 Aralık 2019 Cuma

Ethernet II MAC Adresi

Giriş
Layer 2 switch'ler MAC adreslerini değiştirmezler.

Şekli
MAC Adresi şu şekildedir
00-14-22-01-23-45
İlk üç hane yani
00-14-22
üreticiyi belirtir yani Organizationally Unique Identifier (OUI) kısmıdır. Blokların bir kısmı IANA bir kısmı da IEEE kontrolünde. Diğer üreticilerin listesi şöyle.

Kod
MAC adresini hexadecimal olarak yazdırmak için şöyle yaparız.
std::string Mac::to_string() const
{
  std::ostringstream s;
  s << std::hex << std::setfill('0');
  std::string colon = "";
  for (size_t i = 0; i < mac_addr.size(); i++)
  {
    s << std::setw(0) << colon
      << std::setw(2) << (unsigned int)mac_addr[i];
      colon = ":";
  }

  return s.str();
}
Multicast - Genel
Hedef MAC adresin ilk byte'ının ilk bitinin 1 olması bu paketin multicast veya broadcast olduğunu belirtir.
- IG Biti paragrafında bu anlatıldı. Bu yüzden tüm multicast MAC adresleri 01 veya 33 ile başlar.
- İlk byte'ın ikinci bitinin 0 olması da LG Biti paragrafında anlatıldı

Multicast Olması - IPv4
Ethernet frame'inin tipi ETH_P_IP olmalıdır. Açıklaması şöyle.
The IPv4 multicast Ethernet range is 01:00:5E (224.0.0.0/4). As an example, Some multicast IP used by OSPF are 224.0.0.5 and 224.0.0.6. Related MAC are 01-00-5E-00-00-05 and 01-00-5E-00-00-06 (note that the bit 0 is set to 1). The broadcast MAC FF:FF:FF:FF:FF:FF is another example (note that most switch treat multicast and broadcast frame the same way).
Multicast adresleri hep şöyle başlar. Takip eden byte'taki 8. bit te 0'dır. Yani toplam 25 bit kullanılır. IPv4 multicast adresi için 23 bit kalır.
01-00-5e
Bu blok IANA'ya aittir. Geriye kalan 3 byte yani 00-00-00 ve 7F-FF-FF arası değerler multicast  adresi için olarak kullanılıyor. Dolayısıyla MAC seviyesinde multicast için sadece 23 bit kullanılabilir. IP seviyesinde ise multicast adresi 224/4 olarak tanımlı yani 28 bit uzunluğunda. Dolayısıyla her zaman 28 biti 23 bite sığdırmak problemi var.

Multicast Olması - IPv6
Ethernet frame'inin tipi ETH_P_IPV6 olmalıdır. Multicast adresleri hep şöyle başlar.
33:33. Yani toplam 16 bit kullanır. IPv6 multicast adresi için 32 bit kalır.

Broadcast Olması
Adresin tamamen 0XFF yani 255 olmasıdır

IG Biti - İlk Byte'ın İlk Biti
Individual or Group biti demek. "First least significant bit of the first octet is 1." Açıklaması şöyle.
The least-significant bit is the I/G (Individual/Group) flag. Having this bit clear means that the frame is sent to an individual host, and having it set means that it is intended for a group of hosts (broadcast or multicast).
Eğer bu bit 1 ise broadcast veya multicast demektir. 0xFF:0xFF:0xFF:0xFF:0xFF:0xFF broadcast değeri bu alana 1 değerini atar. 0x1:0x00:0x5E multicast değeri de bu alana 1 değerini atar.

LG Biti - İlk Byte'ın İkinci Biti
MAC adresinin üretici tarafından değil kullanıcı tarafından atandığını gösterir. "Second least significant bit of the first octet is 1." Açıklaması şöyle
1.Official MAC addresses have the second-lowest bit of the first octet cleared.
2.Locally administered MAC addresses have the second-lowest bit of the first octet set - it's your responsibility to make them unique.

5F-00-AD and 6A-7D-00 are administered locally
0 ise üretici, 1 ise kullanıcı tarafından atanmıştır. Bu bitin bir işe yaradığını görmedim.

Yani 0X2 ile masklanır. Benim normal ethernet kartımın adresi B4 ile başlıyor. Yani 1011 0100
Sanal makinenin ise 00 ile başlıyor. Yani Local MAC değil.

Sanal Makineler İçin MAC
Sanal makine sağlayıcıları da MAC üretmek için kendilerine atanan OUI numarasını kullanırlar. MAC adresinin son 3 hanesi rastgele seçilir. Bu durumda iki MAC adresinin çakışma ihtimali 2'24'tür yani düşüktür.

4 Aralık 2018 Salı

Ethernet II Frame

Giriş
İlki 1978 yılında Xerox, Intel ve DEC tarafından geliştirilmiştir. Yapısı şöyledir.
+-----------+-------+---------+---------+--------+------------------+---------+ 
|  Preamble |  SFD  |   DA    |   SA    |   TL   | Data (Payload)   | CRC-32  | 
|  6 bytes  |1 Byte | 6 bytes | 6 bytes |2 bytes | 46 to 1500 bytes | 4 bytes |
+-----------+-------+---------+---------+--------+------------------+---------+
Kod ile şöyledir.
/* Ethernet addresses are 6 bytes */
#define ETHER_ADDR_LEN  6

/* Ethernet header */
struct ethheader {
    u_char  ether_dhost[ETHER_ADDR_LEN];    /* destination host address */
    u_char  ether_shost[ETHER_ADDR_LEN];    /* source host address */
    u_short ether_type;                     /* IP? ARP? RARP? etc */
};
Neden Frame Olarak Adlanrılıyor
Geleneksel olarak Layer 2'deki veri Frame, Layer 3'teki veri ise Packet olarak adlandırılıyor.
A Frame is a combination of the L2 header and the Data being carried
A Packet is a combination of the L3 header and the Data being carried.

Flow Control
Layer 2'de genellikle flow control olmaz. Ancak pause frame denilen ve beniö hiç görmediğim bir frame türü de varmış. Bu frame storage network'lerde kullanılıyor deniliyor. Açıklaması şöyle
The first and most commonly implemented flow control system for Ethernet used "pause frames". Pause frames were intended as a means of implementing "back pressure" within the Ethernet network so that switch buffers did not overflow as the speed of sending nodes was limited to what the downstream devices could tag. Unfortunately they created problems where one congested flow could cause blocking of other uncongested flows, so they are often disabled in practice.
Random Access Özelliği
Ethernet random access özelliğini Aloha'dan miras almıştır. Ethernet'te Flow Control denilen bir mekanizma var ama ne olduğunu tam anlamadım.

Frame şu kısımlardan oluşur.
Preamble | Delimiter | Mac Headers | Payload | Pad | CRC
Switch
Ethernet artık bus yapısında değil. Modern switch'ler sadece ilgili MAC adresine giden port'a veri gönderilmesini sağlıyorlar. Bazı cihazlar yığıt şeklinde (switch stack) bile kullanılabiliyor.

Physical Layer
Fiziksel katman (Physical Layer) elektriksel hataları ele alıyor. Bu hatyı MAC'e bildirir. MAC FrameCheckError üretir ve paketi işlemez.

Büyüklüğü 
En büyük
Bir Ethernet II paketi FCS hariç en fazla 1514 byte uzunluğunda olabilir. 1500 byte veri + 14 byte Mac Headers. FCS 4 byte uzunluğundadır ancak çoğu ethernet sürücüsü FCS'i okumaya izin vermez.

En küçük
İlaveten bir ethernet II paketi FCS hariç en az 60 byte uzunluğunda olmalıdır. 14 byte header Mac Headers alanını çıkarırsak 46 byte veri taşıyabilir. Eğer gönderilen veri 46 byte'tan küçükse etherhet sürücüsü veriyi otomatik olarak 46 byte olacak şekilde boş byte ile doldurur. Açıklaması şöyle.
IEEE 802 packets may have a minimum size restriction. When necessary, the data field should be padded (with octets of zero) to meet the IEEE 802 minimum frame size requirements. This padding is not part of the IP datagram and is not included in the total length field of the IP header.
Wireshark bu doldurulan alanı Trailer olarak gösterir. Çıktı olarak şuna benzer bir şey görürüz.
Ethernet II
Destination: Broadcast (ff:ff:ff:ff:ff:ff)
Source: c4:46:19:1d:05:f6 (c4:46:19:1d:05:f6)
Type: ARP (0x0806)
Trailer: D01CCF9087084E0A00000000000000000000

Address Resolution Protocol (reply)
Hardware type: Ethernet (0x0001)
Protocol type: IP (0x0800)
Hardware size: 6
Protocol size: 4
Opcode: reply (0x0002)
[Is gratuitous: False]
Sender MAC address: c4:46:19:1d:05:f6
Sender IP address: 88.200.89.1
Target MAC address: ff:ff:ff:ff:ff:ff
Target IP address: 0.0.0.0
1. Preamble ve Delimeter
Açıklaması şöyle.
The preamble is actually 7 octets,followed by a start frame delimiter (SFD). They just mark that a frame is coming and serve synchronisation purposes, they are not part of the frame.
Preamble + Delimeter toplam 8 byte uzunluğundadır.

1.1 Preamble
Preamble 7 byte uzunluğundadır. 56 bit'lik 1-0-1-0'lardan oluşur.

1.2 Start Frame Delimeter
Start Frame Delimeter ise 1 byte yani 8 bit uzunluğundadır. 10101011 değerindedir. Decimal olarak 171, hexadecimal olarak 0XAB değerindedir. En sondaki bit 1-0 yerine 1-1'dir.

Böylece preamble + SFD ile 64 bit yani 8 byte'a erişilir.

Preamble ve Start Frame Delimeter alanları tamamen Layer 1 ile alakalı oldukları için okumak imkansız.

TDMA'de kullanılan bir preamble değeri şöyle
0x749713BF

2. MAC Header
14 byte uzunluğundadır. Linux'ta ethernet paketi <netinet/ether.h> dosyasında tanımlıdır.
+----+----+------+------+-----+
   | DA | SA | Type | Data | FCS |
   +----+----+------+------+-----+
             ^^^^^^^^

   DA      Destination MAC Address (6 bytes)
   SA      Source MAC Address      (6 bytes)
   Type    Protocol Type           (2 bytes: >= 0x0600 or 1536 decimal)  <---
   Data    Protocol Data           (46 - 1500 bytes)
   FCS     Frame Checksum          (4 bytes)

2.1 DA ve SA
Source ve Destination MAC adresleri özel programlama gerektirmez. Daha detaylı bilgi için Ethernet II MAC Adresi yazısına bakabilirsiniz.

2. 2 Type

Ethernet II Frame ve  IEEE802.3 Ayrımı Nasıl Yapılır
Eğer bu alanın değeri >=1536 ise Ethernet II Frame, <=1500  IEEE802.3 frame anlamına gelir. >1500 ve <1536 arasındaki değerler tanımsızdır.

Ethernet II Frame Açısında Bu Alana Taşınan Paket Tipini Belirtir
Bu alan taşınan paket tipini belirtir. Açıklaması şöyle.
EtherType value of 0x0800 signals that the frame contains an IPv4 datagram. Likewise, an EtherType of 0x0806 indicates an ARP frame, 0x86DD indicates an IPv6 frame and
0x8100 indicates the presence of an IEEE 802.1Q tag
Bu alan sayesinde Ethernet II Frame genel (generic) olarak kullanılabiliyor. Açıklaması şöyle.
A key goal of Ethernet was ubiquity -- in order to be cheap it had to be everywhere, and so it was designed to be completely neutral about its contents.

Örnek
Eğer bu alan 0x88E5 ise MACsec frame'dir.

Örnek - C Kodu
Ethernet Type alanı ntohs ile okunur.
if(ntohs(eth_hdr->eth_type) == ETH_P_ARP) //0X806 yani 2054
veya
if(ntohs(eth_hdr->eth_type) == ETH_P_IP) //0X800 yani 2048
Şöyle yaparız.
if (eth_hdr->eth_type != ntohs(0x0800)) return; //this is not an IP packet
3. Data
Paketin büyüklüğü 14 byte uzunluğundadır.
/* ethernet headers are always exactly 14 bytes */
#define SIZE_ETHERNET 14
Paket IP ise şöyle yaparız.
struct ethheader *eth = ...;
struct ipheader* ip = (struct ipheader*)(packet + SIZE_ETHERNET); 
4. FCS
Açıklaması şöyle
Ethernet has 32-bit CRC called frame check sequence (FCS). This is very reliable: for random corruption, it means that 1 in 4 billion packets gets accidentally accepted even though it contains corrupted data. Considering that one packet is typically about a kilobyte, this means that random corruption corrupts your data once per 4 terabytes of corrupted data sent. Unfortunately, Ethernet's FCS is not true end-to-end checksum.
FCS tüm frame'in CRC'sini içerir. Açıklaması şöyle
For data link layers (the 2 most common being 802.3 and 802.11), the FCS will detect single bit errors anywhere in the entire frame.

The header checksum in an IP packet only detects errors in the header. There is no trailing checksum in IP. It's up to the upper layers to detect errors in the payload.
Açıklaması şöyle
The FCS is a CRC over all fields (except the FCS) with the polynomial

G(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1