26 Mart 2019 Salı

Carrier Sense Multiple Access With Collision Avoidance - CSMA/CA

Giriş
Temel olarak CSMA/CA da yayın yapmaya başladıktan sonra collision olup olmadığını anlamanın yolu yok. Bu yüzden paketin gidip gitmediğini anlamak için Acknowledgement paketleri kullanıyor.

Hattın Boş Olduğunu Anlamak
Açıklaması şöyle.
IEEE 802.11 releases use CSMA/CA (Collision Avoidance) instead of CSMA/CD (Collision Detection) which is used in wired networks.

OFDM, on the other hand, is just an advanced digital modulation scheme which divides the data stream being exchanged between the node and the AP to multiple individual streams of lower rate and transmits them on different, closely-spaced carrier frequencies simultaneously (multiplexing). Making the signal more robust against error--thus allowing higher data rates--is what OFDM does in a nutshell.
Açıklaması şöyle.
802.11 is half-duplex. This means that only once device can talk at a time, even with one client device, this means there are two devices that must share the "airtime" (i.e. number of timeslots available to transmit) when trying to transmit.
Hat Boş Değilse
Bir bekleme süresi algoritması çalıştırılıyor. Açıklaması şöyle.
In CSMA/CA, as soon as a node receives a packet that is to be sent, it checks to be sure the channel is clear (no other node is transmitting at the time). If the channel is clear, then the packet is sent. If the channel is not clear, the node waits for a randomly chosen period of time, and then checks again to see if the channel is clear. This period of time is called the backoff factor, and is counted down by a backoff counter. If the channel is clear when the backoff counter reaches zero, the node transmits the packet. If the channel is not clear when the backoff counter reaches zero, the backoff factor is set again, and the process is repeated.
Kontrol Mesajları
Kontrol mesajları ile ilgili açıklama şöyle. Kontrol mesajları sanırım opsiyonel.
The physical characteristics of WiFi make it impossible and impractical for the CSMA/CD mechanism to be used. This is due to CSMA/CD’s nature of ‘listening’ if the medium is free before transmitting packets. Using CSMA/CD, if a collision is detected on the medium, end-devices would have to wait a random amount of time before they can start the retransmission process. For this reason, CSMA/CD works well for wired networks, however, in wireless networks, there is no way for the sender to detect collisions the same way CSMA/CD does since the sender is only able to transmit and receive packets on the medium but is not able to sense data traversing that medium. Therefore, CSMA/CA is used on wireless networks. CSMA/CA doesn’t detect collisions (unlike CSMA/CA) but rather avoids them through the use of a control message. Should the control message collide with another control message from another node, it means that the medium is not available for transmission and the back-off algorithm needs to be applied before attempting retransmission.
802.11 mesajları ile ilgili açıklamaı şöyle.
There are three main types of frames
- Data Frames : which are used for data transmission
- Control Frames : which are used to control access to the medium (e.g. RTS,CTS and ACK), and
- Management Frames : which are frames that are transmitted the same way as data frames to exchange management information, but are not forwarded to upper layers

Each of these types is as well subdivided into different Subtypes, according to their specific function
RTS/CTS mesajları ile ilgili açıklama şöyle.
CSMA/CA can optionally be supplemented by the exchange of a Request to Send (RTS) packet sent by the sender S, and a Clear to Send (CTS) packet sent by the intended receiver R. Thus alerting all nodes within range of the sender, receiver or both, to not transmit for the duration of the main transmission. This is known as the IEEE 802.11 RTS/CTS exchange. Implementation of RTS/CTS helps to partially solve the hidden node problem that is often found in wireless networking.[7][8]
Hidden Node Problem
Açıklaması şöyle.
Then "hidden-node-problem", which happens when the clients A & C are connected with the router B, but can't "hear" each other due to the distance between them (f.e. each of them is on the other side), so they are "listening" and don't hear anything (Also if the other client is sending) and therefore just send their data with a collision as a result.

Matris Sınıfı

3 Boyutlu Matris
Şöyle yaparız. Koordinatlardan belleğe, bellekten koordinatlara erişim imkanı verir.
template<class T>
class Matrix3D // minimal
{
public:
    using value_type = T;
    using iterator   = std::vector<value_type>::iterator;

private:
    std::vector<value_type> _data;
    size_t _sizex, _sizey, _sizez;

    size_t index_from_coords(size_t x, size_t y, size_t z) const
    {
        return x*_sizex*_sizey + y*_sizey + z;
    }
    std::tuple<size_t, size_t, size_t> coords_from_index(size_t index) const
    {
        const size_t x = index / (_sizex * _sizey);
        index = index % x;
        const size_t y = index / _sizey;
        const size_t z = index % _sizey;
        return make_tuple(x, y, z);
    }
public:
    Matrix3D(size_t sizex, sizey, sizez) : _sizex(sizex), ... {}
    T& operator()(size_t x, size_t y, size_t z) // add const version
    {
        return _data[index_from_coords(x, y, z)];
    }
    std::tuple<size_t, size_t, size_t> coords(iterator it)
    {
        size_t index = std::distance(begin(_data), it);
        return coords_from_index(index);
    }
    iterator begin() { return begin(_data); }
    iterator end()   { return end(_data);   }
}
Şöyle yaparız.
Matrix3D<double> m(3, 3, 3);
auto it = std::max_element(m.begin(), m.end()); 
auto coords = m.coords(it);
std::cout << "x=" << coords.get<0>() << ... << "\n";
Çarpım
Elimizde şöyle bir kod olsun
// dimensions
int m = 4;
int n = 5;
int p = 3;

// 'a' is an 'm×n' matrix
int[][] a = {
        {2, 4, -1, 7, 9},
        {-2, -6, 6, 4, 3},
        {3, 8, 2, 7, -5},
        {8, 5, 3, 2, -7}};

// 'b' is an 'n×p' matrix
int[][] b = {
        {3, -2, 1},
        {8, 0, -9},
        {2, 5, 7},
        {-1, 6, 9},
        {3, -3, 5}};
Şöyle yaparız. İki tane iç içe döngü kurmak yerine IntSream kullanılıyor.
// 'c' is an 'm×p' matrix
int[][] c = IntStream.range(0, m)
        .mapToObj(i -> IntStream.range(0, p)
                .map(j -> IntStream.range(0, n)
                        // multiply the entries
                        // of the i-th row of 'a'
                        // and the j-th column of 'b'
                        .map(k -> a[i][k] * b[k][j])
                        // the sum of the products
                        .sum())
                .toArray())
        .toArray(int[][]::new);
Tersçapraz (Transpose)
- Satırları sütun haline getirmek veya
- Sütunları yukarıdan aşağıya dolaşarak her elemanı yeni bir satıra eklemek 
anlamına gelir.

Örnek
Şöyle yaparız
std::vector<double> transpose_vector(const std::vector<std::vector<double>> &column_vec){
  std::vector<double> row_vector;
  row_vector.reserve(total_entries(column_vec)); // Pre-allocate the space we need

  for (auto c : column_vec) {
    for (auto r : c) {
      row_vector.push_back(r);
    }
  }
  return row_vector;
}
Örnek
Şöyle yaparız.
public class Matrix
{

  private double[][] A;// 2-D array to hold matrix element
  private m,n ; // number of column and row.
 
  public Matrix transpose () {
    Matrix X = new Matrix(n,m);
    double[][] C = X.getArray();
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        C[j][i] = A[i][j];
      }
    }
    return X; 
                
  }

  public double[][] getArray () {
    return A;
  }       

}
Aslında 3 tane liste var ve bunların zip()'i alıyoruz diye düşünülebilir.