1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation;
- import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
- import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
- /**
- * Simple dummy packet for testing purposes
- *
- * @author Andreas T. Meyer-Berg
- */
- public class SimplePacket extends Packet {
- /**
- * Payload which was sent
- */
- private String payload;
- /**
- * Creates a new dummy packet without payload
- *
- * @param time
- * time the package was created in System.currentTimeMillis
- * @param source
- * SmartDevice which sent this packet
- * @param destination
- * SmartDevice which should receive this packet
- */
- public SimplePacket(long time, Port source, Port destination) {
- super(time, source, destination);
- this.payload = "";
- }
- /**
- * Creates a new dummy packet with a String as payload
- *
- * @param time
- * time the package was created in System.currentTimeMillis
- * @param source
- * SmartDevice which sent this packet
- * @param destination
- * SmartDevice which should receive this packet
- * @param payload
- * String which represents the payload which is encapsulated by
- * this packet
- */
- public SimplePacket(long time, Port source, Port destination, String payload) {
- super(time, source, destination);
- this.source = source;
- this.destination = destination;
- this.payload = payload;
- }
- @Override
- public byte[] dumpBytes() {
- return this.dumpBytes();
- }
- @Override
- public String getTextualRepresentation() {
- return this.toString();
- }
-
- @Override
- public String toString() {
- String destName = destination == null ? "null" : destination.getOwner().getName();
- String srcName = source == null ? "null" : source.getOwner().getName();
-
- return "[SimplePacket:" + payload + " time-" + timestamp + ";source:" + srcName + ";dest:"
- + destName + "]";
- }
- @Override
- public String getPayload() {
- return payload == null ? "" : payload;
- }
- @Override
- protected String getProtocolName() {
- return "Simple";
- }
- }
|