ANTS v2.0 API

ants.core
Class DataCapsule

java.lang.Object
  |
  +--ants.core.Capsule
        |
        +--ants.core.DataCapsule
Direct Known Subclasses:
PingCapsule, PongCapsule, StatsReturnCapsule

public class DataCapsule
extends Capsule

Data capsule. Data capsules simply forward themselves to their destination. Each DataCapsule contains source and destination application ports (in addition to the source and destination node addresses kept by the superclass). Also, an arbitrary ByteArray payload is attached to the capsule.

XXX This doesn't need to be a builtin capsule type. Its convenient and all, but its not critical. Move it out to the apps/ directory. (Well, the fact that its builtin means the ID is fixed, so this is handy in a backwards-compatiblity way.)

Author:
David Wetherall

Field Summary
 short dpt
          Destination application's port.
 short spt
          Source application's port.
static java.lang.String VERSION
          WARNING: this is a builtin capsule, whose version number must be manually kept in synch with its functionality.
 
Fields inherited from class ants.core.Capsule
MAX_TTL
 
Constructor Summary
DataCapsule()
           
DataCapsule(short s, short d, int n, ByteArray p)
          Construct a new DataCapsule.
 
Method Summary
 Xdr decode()
          Decode a capsule header from this Capsule's xdr field.
 Xdr encode()
          Encode this capsule's header into a new Xdr.
 boolean evaluate(Node n)
          Forwarding function for DataCapsules.
 ByteArray getData()
          Get the payload associated with this DataCapsule.
 int length()
          Return length of this data capsule.
 void setData(ByteArray data)
          Set the payload associated with this DataCapsule.
 java.lang.String toString()
          String representation of a Capsule.
 
Methods inherited from class ants.core.Capsule
create, encodeCapsuleForSend, findExtension, findMID, findPID, getDst, getPrevious, getSrc, getTTL, prime, setDst
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
WARNING: this is a builtin capsule, whose version number must be manually kept in synch with its functionality.
See Also:
BuiltinProtocol#addCapsule(java.lang.String,java.lang.String)

spt

public short spt
Source application's port.

Not used by the DataCapsule, but its assumed that most users of this type will want to know where the capsule came from.


dpt

public short dpt
Destination application's port.
Constructor Detail

DataCapsule

public DataCapsule()

DataCapsule

public DataCapsule(short s,
                   short d,
                   int n,
                   ByteArray p)
Construct a new DataCapsule.
Parameters:
s - the source application's port
d - the destination application's port
n - the address of the destination node.
p - the payload.
Method Detail

length

public int length()
Return length of this data capsule.
Overrides:
length in class Capsule
See Also:
Capsule.length()

encode

public Xdr encode()
Description copied from class: Capsule
Encode this capsule's header into a new Xdr. Return the new Xdr.

Because this header must go first in the Xdr, this encoder unilaterally sets the xdr buffer pointer to the beginning of the buffer and writes its data there.

The format of the Xdr is:

 MethodID         (16 bytes)
 src address      ( 4 bytes)
 dst address      ( 4 bytes)
 previous address ( 4 bytes)
 TTL              ( 4 bytes)
 
Overrides:
encode in class Capsule
Tags copied from class: Capsule
Returns:
the new Xdr representing this capsule.
See Also:
#xdr

decode

public Xdr decode()
Description copied from class: Capsule
Decode a capsule header from this Capsule's xdr field.
Overrides:
decode in class Capsule
Tags copied from class: Capsule
Returns:
the new Xdr based on the current xdr.

getData

public ByteArray getData()
Get the payload associated with this DataCapsule.

setData

public void setData(ByteArray data)
Set the payload associated with this DataCapsule.

evaluate

public boolean evaluate(Node n)
Forwarding function for DataCapsules. Forwards the capsule to the appropriate application port if the capsule is on its destination node, otherwise forwards the capsule on to its destination node.
Overrides:
evaluate in class Capsule
Tags copied from class: Capsule
Parameters:
node - the local node interface
Returns:
an indicationof whether the forwarding was successful.

toString

public java.lang.String toString()
Description copied from class: Capsule
String representation of a Capsule. Includes the class name, source and destination.
Overrides:
toString in class Capsule

ANTS v2.0 API

This documentation is Copyright (C) 1998-2001 The University of Utah and the University of Washington. All Rights Reserved. See the individual source files for distribution terms.
Documentation, software, and mailing lists for ANTS v2.0 can be found at the Janos Project: http://www.cs.utah.edu/flux/janos/