Multi-routing the '.Net' - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

Multi-routing the '.Net'

Description:

Stream Sockets in C#.NET http://pooh.east.asu.edu/Cet556/ClassNotes/Serial ... http://pooh.east.asu.edu/Cet556/ClassNotes/Serial/cnSerialThreadSocket-25.h tml ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 30
Provided by: csU75
Learn more at: http://www.cs.uccs.edu
Category:
Tags: multi | net | pooh | routing

less

Transcript and Presenter's Notes

Title: Multi-routing the '.Net'


1
Multi-routing the '.Net'
  • Gigax, Kevin Edward
  • Torres, Francisco Javier
  • CS522 Computer Communications

2
Project Goals
  • The Goal of this project is to enable
    multi-routing in a Microsoft .NET environment
    using the C language.
  • The projects initial phase is to implement
    multi-routing using routes that are hard-coded
    into the servers.
  • In the future, the project plans to implement
    multi-routing to any server running the .NET
    framework.

3
Description
  • The project calculates the bandwidth from a
    source server through n different routes to a
    destination server.
  • The project will be expanded to route through
    multiple servers in the future.

4
Function Call getBandwidth Finds the fastest
route from S1 to D1 using specific servers
R1
S1
D1
R2
Rn
5
Function Call getBandwidth2 Finds the fastest
route from S1 to D1 using x amount of servers
R12
R13
R11
S1
D1
R21
R22
Rn1
Rnn
6
Implementation
  • The software design uses a software created
    packet of x bytes. This packet is transmitted
    across the network using a socket connection as
    an ICMP packet.
  • The software times the amount of time for the
    packet to be transmitted and for a reply to be
    received. This timing is the estimated bandwidth
    of that route.
  • The routers are hard-coded into the servers as
    character arrays. Each router in the array is
    tested for its bandwidth abilities.

7
Implementation
  • Function Calls
  • getBandwidth(sourceServer, destinationServer,
    routingServer)
  • For each proxy server available, call
    getBandwidth function
  • Once an acceptable bandwidth is found exit call
    and use this proxy server
  • findBandwidth(sourceServer, destinationServer)
  • Execute a packet send and receive to the source
    and to the destination
  • Time the packets total round trip time

8
Drawbacks
  • The primary drawbacks of the project are as
    follows
  • Congesting the network if we continual send out
    queries for bandwidth, we start to cause serious
    network congestion
  • Estimated Bandwidth available bandwidth is a
    large topic and we cannot insure that this is the
    best way to find the bandwidth of a connection

9
Performance Analysis
  • Waiting for multiple queries highly degrades
    performance
  • We need to implement multi-threaded queries to
    solve this
  • Getting the absolute best bandwidth can also
    degrade performance
  • We can set an acceptable bandwidth value and stop
    the queries once we find a bandwidth that is gt
    to this value

10
Socket connections in .NET
  • How to create both ends of a TCP/IP socket
    connection between two or more applications?

11
  • Sequence of events

12
  • Why use sockets in .NET?
  • .NET uses sockets in many instances as Web
    services and remoting, but here the low level
    stuff is done for us.
  • However, when interfacing with other non .NET
    system, sockets are a necessary and simple
    communication method.

13
Why use Stream Sockets?
  • Stream Sockets (TCP)
  • Session (or connection) based service
  • Guarantees that packets are sent without
    errors, sent (and received) in sequence and
    without duplication
  • Unlimited data size in packets
  • Communication between server and client occurs
    through streams
  • The base class for this communication is
    NetworkStream .
  • Streams can be used for binary, text, and
    string data or serialized objects.
  • Datagram sockets are supported by class
    System.Net.Sockets.UDPClient

14
  • Scenario for Stream Sockets
  • Sockets are created by both client and server,
  • Server specifies a port number
  • Server may customize aspects of connections
    (wait queue, etc)
  • Client specifies the internet address and port
    in creating its socket. In C, when the client
    creates its TCPClient instance, a connection is
    established with the TCPListener

15
  • Scenario (continued)
  • Server listens for arriving requests (
    AcceptSocket or AcceptTcpClient method) to
    establish a session (connection) with a client.
  • If no connections are pending, the server
    blocks . If one or more clients are waiting, they
    are queued and in turn, the server creates a new
    thread (stay tuned) to service each client. The
    parent thread re-issues the accept to service
    another client on the same socket.
  • The client and server identify input and output
    streams for passing information according to a
    protocol they both agree to. The input and output
    streams perform the work of the application.
  • The client and server must both close the
    connection to allow resources to be used in
    another connection.

16
  • .NET sample socket Client and Server

17
  • Socket Server
  • using System.Net.Sockets
  • using System
  • /// ltsummarygt
  • /// Example program showing simple TCP socket
    connections in C.NET.
  • /// TCPSocketServer is the socket server.
  • /// lt/summarygt
  • public class TCPSocketServer
  • public static void Main (string args)
  • TcpListener tcpl new TcpListener(9090)
  • tcpl.Start()
  • Console.Write("TCPSocketServer up and waiting
    for connections on 9090")
  • Socket sock tcpl.AcceptSocket()
  • string msg "Hello Client"
  • Byte msgBytes System.Text.Encoding.ASCII.G
    etBytes(msg)
  • sock.Send(msgBytes, msgBytes.Length,
    SocketFlags.DontRoute)
  • tcpl.Stop()

18
  • Socket Client
  • using System
  • using System.IO
  • using System.Windows.Forms
  • using System.Net.Sockets
  • /// ltsummarygt
  • /// Example program showing simple TCP socket
    connections in C.NET.
  • /// TCPSocketClient is the socket client.
  • /// lt/summarygt
  • public class TCPSocketClient
  • public static void Main (string args)
  • TcpClient tcpc new TcpClient("localhost",
    9090)
  • Stream tcpStream tcpc.GetStream()
  • StreamReader reader new StreamReader(tcpStre
    am,

  • System.Text.Encoding.ASCII)
  • MessageBox.Show(reader.ReadLine())
  • reader.Close()

19
Thread Concept
  • Why threads?

20
  • Threaded Socket Servers
  • How does a threaded socket server, for protocols
    such as http or ftp, allow multiple clients to be
    simultaneously connected to the server?

21
  • What is a Thread?
  • A thread is a single sequential flow of control
    within a program
  • A multi-threaded program
  • Two or more threads seemingly active
    simultaneously
  • All within the overhead of a single executing
    C program
  • A single starting point and ending point for
    all threads in the program and for the program
    itself.

22
  • Other Threading capabilities
  • Thread.Join() method - used to wait for another
    thread to complete.
  • Sleep -- suspend for a number of milliseconds
    Thread.Sleep(2000)
  • Thread States Thread includes a property to
    query a state.
  • Priorities - .NET supports 1 to 10 lowest to
    highest priorities
  • Volatile modifier for attributes (don't cache)
    multi-CPU one RAM.

23
  • Synchronization.
  • What is a Shared Object ?
  • Multiple threads of single program may
    access or change the same object.
  • When should access to shared objects be
    controlled ?
  • When multiple threads only read the object
    - no synchronization .
  • If any thread modifies the object -
    synchronization is necessary.
  • Why must access be controlled when some thread
    changes the object?
  • consider stack.push(item) , for example
  • multiple actions are necessary to achieve
    consistent state, for example
  • (1) increment stack pointer
  • (2) place the new item into the collection
    using the stack pointer.
  • If one thread is interrupted after step 1,
    but before step 2 , then another thread may see
    an inconsistent stack state (visualize a
    stack.top() ).
  • Monitor - a lock used to protect a critical
    section of code
  • Each thread calls Enter() to get the lock
    before push(item)
  • Each thread calls Exit() to release the
    lock after push(item) completes

24
  • C .NET Monitors
  • A Monitor protects access to the Object
  • See System.Threading.Monitor class
  • All Monitor methods are static
  • Basic Monitor methods to lock and unlock an
    object
  • void Enter(object) and bool TryEnter(object,
    TimeSpan) lock the object. A thread may be
    recursive (call multiple Enter's before first
    Exit)
  • void Exit(object) indicate the calling thread
    is ready to unlock the object

25
  • Issues with Multi-Threaded programs
  • Synchronization - "I can't go past this statement
    until another thread reaches that statement"
  • Concurrency , parallelism and asynchronous
    behavior
  • Deadlock
  • Threads with shared data (objects)
  • Scheduling and blocking operations, such as input
    and output
  • Underlying support for implementing threads
  • Performance

26
Overview
27
Conclusions
  • Our project progress has reached being able to
    calculate a path from a source to destination
    server using socket connections when the routing
    servers are hard-coded
  • Our continued efforts involve creating actual
    packets and headers to relay through multiple
    paths to increase throughput and researching
    algorithms that locate good paths through the
    internet to a destination server

28
What is next?
  • Find a proper way to calculate the bandwidth.
  • A specific design of threads, server, clients,
    frames headers.
  • Design a bidirectional communication, in order to
    implement a multimedia (voice and sound)
    application.

29
References
  • VisualC Ideas Using Sockets in C
  • http//www.mctainsh.com/Csharp/SocketsInCS.as
    px
  • Stream Sockets in C.NET http//pooh.east.asu.edu/
    Cet556/ClassNotes/Serial/cnSerialThreadSocket-18.h
    tml
  • The Code Project
  • http//www.codeproject.com/csharp/workerthrea
    d.asp
  • Programing with threads in C
  • http//pooh.east.asu.edu/Cet556/ClassNotes/Se
    rial/cnSerialThreadSocket-25.html
  • O'Reilly Network Multithreading with C
  • http//www.ondotnet.com/pub/a/dotnet/2001/08/
    06/csharp.html
  • C Primer A Practical Approach
  • Stanley B. Lippman, Addison-Wesley, 2002
    Pearson Education
  • C Essentials
  • Ben Albahari, Peter Drayton Brad Merril,
    2002 OReilly
Write a Comment
User Comments (0)
About PowerShow.com