?? ipmessage.java
字號:
/* * @(#)$Id: IPMessage.java,v 1.7 2004/07/02 23:59:22 huebsch Exp $ * * Copyright (c) 2001-2004 Regents of the University of California. * All rights reserved. * * This file is distributed under the terms in the attached BERKELEY-LICENSE * file. If you do not find these files, copies can be found by writing to: * Computer Science Division, Database Group, Universite of California, * 617 Soda Hall #1776, Berkeley, CA 94720-1776. Attention: Berkeley License * * Copyright (c) 2003-2004 Intel Corporation. All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE file. * If you do not find these files, copies can be found by writing to: * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, * Berkeley, CA, 94704. Attention: Intel License Inquiry. */package simulator.schedulers.network;import java.net.InetAddress;import services.network.Payload;import util.FreeList;import util.FreeListFactory;import util.network.serialization.GenericByteBuffer;import util.network.serialization.SerializationManager;import util.network.serialization.SerializeInetAddress;/** * Class IPMessage * */public class IPMessage implements Payload { public static long serialVersionUID = SerializationManager.getSerialUID( "simulator.schedulers.network.IPMessage"); public static final int PROTOCOL_TCP = 6; public static final int PROTOCOL_UDP = 17; private static final int IP_MTU = 1500; private static final int IP_OVERHEAD = 20; private InetAddress source; private InetAddress destination; private int protocol; private Payload data; private static FreeList freeList = new FreeList(new IPMessageFactory()); /** * DeSerialize the object from the provided GenericByteBuffer. * * @param inputBuffer */ public IPMessage(GenericByteBuffer inputBuffer) { this.source = SerializeInetAddress.deSerialize(inputBuffer, 4); this.destination = SerializeInetAddress.deSerialize(inputBuffer, 4); this.protocol = inputBuffer.getInt(); this.data = SerializationManager.deSerialize(inputBuffer); } /** * Serialize the object into the provided GenericByteBuffer. * * @param outputBuffer * @return */ public long serialize(GenericByteBuffer outputBuffer) { SerializeInetAddress.serialize(outputBuffer, source); SerializeInetAddress.serialize(outputBuffer, destination); outputBuffer.putInt(protocol); SerializationManager.serialize(outputBuffer, data); return serialVersionUID; } /** * Constructor IPMessage */ protected IPMessage() {} private void init(InetAddress source, InetAddress destination, int protocol, Payload data) { this.source = source; this.destination = destination; this.protocol = protocol; this.data = data; } /** * Method getSource * @return */ public InetAddress getSource() { return source; } /** * Method getDestination * @return */ public InetAddress getDestination() { return destination; } /** * Method getProtocol * @return */ public int getProtocol() { return protocol; } /** * Method getData * @return */ public Payload getData() { return data; } /** * Method getSize * @return */ public int getSize() { int dataSize = SerializationManager.getPayloadSize(data); int numPackets = dataSize / (IP_MTU - IP_OVERHEAD); return dataSize + (numPackets * IP_OVERHEAD); } /** * Method toString * @return */ public String toString() { return "<IP: SR:" + source + ", DE:" + destination + ", DA:" + data + ">"; } /** * Method allocate * * @param source * @param destination * @param protocol * @param data * @return */ public static IPMessage allocate(InetAddress source, InetAddress destination, int protocol, Payload data) { IPMessage message = (IPMessage) freeList.allocate(); message.init(source, destination, protocol, data); return message; } /** * Method free * * @param message */ public static void free(IPMessage message) { freeList.free(message); }}/** * Class IPMessageFactory * */class IPMessageFactory implements FreeListFactory { /** * Method create * @return */ public Object create() { return new IPMessage(); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -