재밌는 툴이 하나 있어서 소개한다.
솔라리스(이하 오픈인디아나)의 ZFS을 GUI로 설정할 수 있는 툴인데, 사실 나온지는 1년 좀 넘었다.
지금은 상용 솔라리스에만 포함된 ZFS Administrator와는 기능상에서 많이 떨어지지만 이러한 툴을 찾고자하는 분들을 위해서 소개해본다.
Napp it 이라고 하는 툴인데, http://www.napp-it.org/ 에서 제작하는 공개 소프트웨어이다.
영어가 불편하신 분들을 위해 설치방법을 소개한다.

먼저 root로 변경한다.
$ su - root

Napp-it을 설치한다. 아래의 명령어만 입력하면 자동으로 설치해준다. 무척이나 편리하다.
# wget -O - www.napp-it.org/nappit | perl
# shutdown -y -i6 -g0 


이후 웹브라우저를 열고 오픈인디아나 서버의 주소를 넣고 포트번호 81번으로 접근을 하면 Napp-it 자체 미니웹서버가 시작페이지를 보여준다. 첫 설치시에는 비밀번호가 없으니 공란으로 접속을 해서 세팅을 해주면 된다.

한 가지 더 재밌는 점은, 오픈인디아나에 애플의 AFP를 쓸 수 있게 해주는 netatalk 패키지를 지원해준다는 점이다.
설치 방법 역시 간단하다.
wget -O - www.napp-it.org/afp | perl
이로써 오픈인디아나로 맥 타임머신 서버 운영이 가능하다.

참고로 Napp-it에서 Apache PHP MySQL 설치도 지원해준다.
wget -O - www.napp-it.org/amp | perl

만약 맥 OS X 10.7 라이언을 사용 중이라면 패치를 해줘야한다.
# wget -O - www.napp-it.org/afp22p6 | perl

블로그 이미지

jswlinux

Seowon Jung의 잡동사니 보관소

,
먼저 자신의 오픈솔라리스 버전이 뭔지 알아야한다.
uname -a를 실행해서 snv 111인지 snv 134인지 확인한다.

만약 111이라면, 134로 업그레이드를 하고나서 오픈인디아나로의 업그레이드가 가능하다. 따라서, 두 번의 업그레이드를 해야한다는 얘긴데, 첫 번째 업그레이드는 하나마나일 정도로 아주 쉽다.

Step 1
먼저 111에서 134로 업그레이드를 시작한다.
pfexec pkg install SUNWipkg SUNWipkg-um SUNWipkg-gui
pfexec pkg set-publisher -O http://pkg.openindiana.org/legacy opensolaris.org
pfexec pkg image-update -v

Step 2
이제 진짜 오픈솔라리스에서 오픈인디아나로 업그레이드를 시작할 차례다.
pfexec pkg set-publisher --non-sticky opensolaris.org
pfexec pkg set-publisher -P -O http://pkg.openindiana.org/dev openindiana.org
pfexec pkg image-update -v --be-name openindiana

이제 새로운 환경으로 재부팅하면 된다.


만약, 오픈인디아나 148에서 151a로의 업그레이드를 원하면 아래를 따른다.
먼저 패키지 배포처를 확인한다.
pfexec pkg publisher 
를 실행해서
openindiana.org (preferred) origin online http://pkg.openindiana.org/dev/ 라고 나오는 것을 확인한다. 나오지 않으면 아래의 명령어를 실행한다.
pfexec pkg set-publisher -O http://pkg.openindiana.org/dev/ openindiana.org

만약 opensolaris라는 문구가 포함된 라인이 출력된다면 아래의 명령어로 삭제한다.
pfexec pkg unset-publisher opensolaris.org

이제 업데이트를 확인할 차례다. 업데이트 사항을 확인만 하고싶으면 아래의 명령어를 수행한다.
pfexec pkg image-update -nv

확인할 필요 없이 바로 진행하고 싶으면 아래의 명령어를 수행한다.
pfexec pkg image-update -v

추가로 덧붙인다면, 새로 업데이트 되는 BE (Boot Environment)의 이름을 바꾸고 싶으면
--be-name 원하는이름
이라고 넣으면 된다. 
블로그 이미지

jswlinux

Seowon Jung의 잡동사니 보관소

,
자바로 만든 UDP Ping 프로그램이다.
서버를 실행할 때 포트번호를 임의로 적어주면 된다.
예) javac PingServer.java && java PingServer localhost 1024

클라이언트의 실행법은 서버의 IP와 포트번호를 적으면 된다.
예) javac PingClient.java && java PingClient localhost 1024

서버의 코드는 Computer Networking, Kurose and Ross, 5th edition에서 작성된 그대로다.

Programming Assignment 3: UDP Pinger Lab

In this lab, you will study a simple Internet ping server written in the Java language, and implement a corresponding client. The functionality provided by these programs are similar to the standard ping programs available in modern operating systems, except that they use UDP rather than Internet Control Message Protocol (ICMP) to communicate with each other. (Java does not provide a straightforward means to interact with ICMP.) 

The ping protocol allows a client machine to send a packet of data to a remote machine, and have the remote machine return the data back to the client unchanged (an action referred to as echoing). Among other uses, the ping protocol allows hosts to determine round-trip times to other machines.

You are given the complete code for the Ping server below. Your job is to write the Ping client.
 

Server:
// File name: PingClient.java
import java.io.*;
import java.net.*;
import java.util.*;

public class PingServer
{
   private static final double LOSS_RATE = 0.3;
   private static final int AVERAGE_DELAY = 100;  // milliseconds

   public static void main(String[] args) throws Exception
   {
      // Get command line argument.
      if (args.length != 1) {
         System.out.println("Required arguments: port");
         return;
      }
      int port = Integer.parseInt(args[0]);

      // Create random number generator for use in simulating
      // packet loss and network delay.
      Random random = new Random();

      // Create a datagram socket for receiving and sending UDP packets
      // through the port specified on the command line.
      DatagramSocket socket = new DatagramSocket(port);

      // Processing loop.
      while (true) {
         // Create a datagram packet to hold incomming UDP packet.
         DatagramPacket request = new DatagramPacket(new byte[1024], 1024);

         // Block until the host receives a UDP packet.
         socket.receive(request);

         // Print the recieved data.
         printData(request);

         // Decide whether to reply, or simulate packet loss.
         if (random.nextDouble() < LOSS_RATE) {
            System.out.println("   Reply not sent.");
            continue;
         }

         // Simulate network delay.
         Thread.sleep((int) (random.nextDouble() * 2 * AVERAGE_DELAY));

         // Send reply.
         InetAddress clientHost = request.getAddress();
         int clientPort = request.getPort();
         byte[] buf = request.getData();
         DatagramPacket reply = new DatagramPacket(buf, buf.length, clientHost, clientPort);
         socket.send(reply);

         System.out.println("   Reply sent.");
      }
   }

   /*
    * Print ping data to the standard output stream.
    */
   private static void printData(DatagramPacket request) throws Exception
   {
      // Obtain references to the packet's array of bytes.
      byte[] buf = request.getData();

      // Wrap the bytes in a byte array input stream,
      // so that you can read the data as a stream of bytes.
      ByteArrayInputStream bais = new ByteArrayInputStream(buf);

      // Wrap the byte array output stream in an input stream reader,
      // so you can read the data as a stream of characters.
      InputStreamReader isr = new InputStreamReader(bais);

      // Wrap the input stream reader in a bufferred reader,
      // so you can read the character data a line at a time.
      // (A line is a sequence of chars terminated by any combination of \r and \n.)
      BufferedReader br = new BufferedReader(isr);

      // The message data is contained in a single line, so read this line.
      String line = br.readLine();

      // Print host address and data received from it.
      System.out.println(
         "Received from " +
         request.getAddress().getHostAddress() +
         ": " +
         new String(line) );
   }
}



Client:
// File name: PingClient.java
import java.util.*;
import java.net.*;
import java.text.*;

public class PingClient
{
    private static final int PING_MESSAGES = 10;
    private static final int TOKEN_TIMESTAMP = 2;
    private static final int MAX_WAIT_TIME = 1000;
    private static final String CRLF = "\r\n";

    public static void main(String[] args) throws Exception
    {
        // If user doesn't input both port number and ip address, the program will display an error message.
        if (args.length != 2)
        {
            System.out.println("usage: java PingClient <Host> <Port>");
            //return;
        }
        
        try
        {
            if(!args[0].isEmpty())
                System.out.println("\nHost: "+args[1]+"\nIP address: "+args[0]+"\n");
        }
        catch(ArrayIndexOutOfBoundsException e)
        {
            System.out.println("Host name and ip address please");
            System.exit(1);
        }
        InetAddress host = InetAddress.getByName(args[0]);
        
        int portNumber = Integer.parseInt(args[1]);
        
        //Create a datagram socket used for sending and recieving UDP packets
        DatagramSocket socket = new DatagramSocket();

        //Set up the maximum time the socket waits for responses
        socket.setSoTimeout(MAX_WAIT_TIME);

        //Construct a ping message to be sent to the Server
        for (int sequence_num = 0; sequence_num < PING_MESSAGES; sequence_num++)
        {
                String message = generatePing(sequence_num);
                DatagramPacket ping_request =
                    new DatagramPacket(message.getBytes(), message.length(), host, portNumber);

                //Send a ping request
                socket.send(ping_request);

                //Datagram packet to hold server response
                DatagramPacket ping_response =
                    new DatagramPacket(new byte[message.length()], message.length());

                //Wait for ping response from server
                try
                {
                        socket.receive(ping_response);
                        printData(ping_response);
                }
                catch (SocketTimeoutException e)
                {
                        System.out.println("No response was received from the server");
                }
                catch (Exception e)
                {
                        //Another unknown error may have occured that can't be handled
                        e.printStackTrace();
                        return;
                }
        }
    }

    private static String generatePing(int sequence_num)
    {
        // For getting current date and time 
        SimpleDateFormat sdfNow = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        String strNow = sdfNow.format(new Date(System.currentTimeMillis()));
        return "PING #" + sequence_num + " " + System.currentTimeMillis() + " ("+strNow+")";
    }

    //Print ping page to standard output stream
    private static void printData(DatagramPacket request) throws Exception
    {
        String response = new String(request.getData());
        String[] tokens = response.split(" ");
        
        //Create sent and received timestamps for RTT
        long sent_timestamp = new Long(tokens[TOKEN_TIMESTAMP]);
        long received_timestamp = System.currentTimeMillis();

        //RTT
        long rtt = received_timestamp - sent_timestamp;

        //Display results
        System.out.print(response+" Received from "+
                request.getAddress().getHostAddress() + " "+"(RTT=" + rtt + "ms)"+CRLF);
    }
}
블로그 이미지

jswlinux

Seowon Jung의 잡동사니 보관소

,