Skip to content

Commit

Permalink
Implementacion de response en Sendmsg.java y ICMPResponse.java
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielaTh committed Nov 27, 2015
1 parent 69f83ab commit 032452e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 25 deletions.
10 changes: 9 additions & 1 deletion src/Entities/Equipment/Equipment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;

import Entities.Network.IMessaging;
import Entities.Network.IPAddressV4;


/**
Expand All @@ -11,5 +12,12 @@
public abstract class Equipment implements IMessaging {

protected ArrayList<Equipment> equipments = new ArrayList<Equipment>();

protected IPAddressV4 associatedIp;
public IPAddressV4 getAssociatedIp() {
return associatedIp;
}

public void setAssociatedIp(IPAddressV4 associatedIp) {
this.associatedIp = associatedIp;
}
}
60 changes: 36 additions & 24 deletions src/Entities/Equipment/Terminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import Entities.Osystem.TerminalOs;
import Entities.Packages.*;

import java.util.Iterator;

import Entities.Network.IPAddressV4;

/**
* Created by efridman on 14/11/15.
*/
public class Terminal extends Equipment {

private TerminalOs operatingSystem;
private IPAddressV4 associatedIp;
private TerminalOs operatingSystem;
private IPAddressV4 ed;

public TerminalOs getOperatingSystem() {
Expand All @@ -19,15 +21,7 @@ public TerminalOs getOperatingSystem() {

public void setOperatingSystem(TerminalOs operatingSystem) {
this.operatingSystem = operatingSystem;
}

public IPAddressV4 getAssociatedIp() {
return associatedIp;
}

public void setAssociatedIp(IPAddressV4 associatedIp) {
this.associatedIp = associatedIp;
}
}

public IPAddressV4 getEd() {
return ed;
Expand All @@ -40,27 +34,45 @@ public void setEd(IPAddressV4 ed) {

@Override
public void receivePacket(Packet<PacketType> packet) {
String message = "";
PacketType responseType = packet.getServiceType().getResponse();
if(packet.getServiceType().isRequest()){
if(responseType instanceof Who){
message = operatingSystem.getDataVersion();
}
Packet<PacketType> response = new ServicePacket<PacketType>(packet.getDestination(),packet.getSource(),responseType,packet.getTtl(),message);
}else{
message = packet.getText();
if(responseType instanceof ICMPResponse){
message = packet.toString();
if(packet.getDestination().equals(associatedIp)){
String message = "";
PacketType responseType = packet.getServiceType().getResponse();
if(packet.getServiceType().isRequest()){
if(responseType instanceof Who){
message = operatingSystem.getDataVersion();
}
Packet<PacketType> response = new ServicePacket<PacketType>(packet.getDestination(),packet.getSource(),responseType,packet.getTtl(),message);
sendPacket(response);
}else{
message = packet.getText();
if(responseType instanceof ICMPResponse){
message = packet.toString();
}
System.out.println(message);
}
System.out.println(message);
}
}

@Override
public void sendPacket(Packet<PacketType> packet) {
// TODO Auto-generated method stub
boolean exists = false;
Packet<PacketType> pktRequest = packet;
for (Equipment equipment : equipments) {
if(equipment.associatedIp.sameNetwork(packet.getDestination())){
exists = true;
break;
}
}

if(!exists){
pktRequest = new RoutePacket<PacketType>(this.associatedIp, this.ed, packet.getServiceType(),
this.operatingSystem.getTtl(),"", packet);

}

for (Equipment equipment : equipments) {
equipment.receivePacket(packet);
equipment.receivePacket(pktRequest);
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/Entities/Packages/ICMPResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ public class ICMPResponse extends PacketType {
public ICMPResponse(){
this.setIsRequest(false);
}

@Override
public PacketType getResponse() {
// TODO Auto-generated method stub
return null;
}
}
6 changes: 6 additions & 0 deletions src/Entities/Packages/Sendmsg.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ public class Sendmsg extends PacketType {
public Sendmsg(){
this.setIsRequest(false);
}

@Override
public PacketType getResponse() {
// TODO Auto-generated method stub
return null;
}
}

0 comments on commit 032452e

Please sign in to comment.