Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions ARP/src/ARPLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,35 @@ public static void PrintMsg(byte[] input) {

// Receive 함수
public boolean Receive(byte[] input) {
<<<<<<< HEAD
byte[] request = new byte[28];
System.arraycopy(input, 0, request, 0, input.length);

//source mac
byte[] srcMacAdd = new byte[6];
System.arraycopy(input, 8, srcMacAdd, 0, 6);

//source ip
byte[] srcIpAdd = new byte[4];
System.arraycopy(input, 14, srcIpAdd, 0, 4);

//destination ip
byte[] dstIpAdd = new byte[4];
System.arraycopy(input, 24, dstIpAdd, 0, 4);

if(input[7] == 0x01) {
if(IsInArpCacheTable(srcIpAdd)) {
UpdateARPCache(srcIpAdd, srcMacAdd, true);
}
else {
AddARPCache(srcMacAdd, srcMacAdd, true);
}

if(IsMyIP(dstIpAdd) || IsInProxyTable(dstIpAdd)) {
ReplySend(request);
}

=======
System.out.print("메세지 받는중 : ");
byte[] opCode = Arrays.copyOfRange(input, 6, 8);
byte[] SenderMac = Arrays.copyOfRange(input, 8, 14);
Expand Down Expand Up @@ -279,6 +308,7 @@ else if(IsMyIP(TargetIP) || IsInProxyTable(TargetIP)) {
}
UpdateARPCache(SenderIP, SenderMac, true);
GUI_LAYER.GetArpTable(); // ARP Table 업데이트
>>>>>>> upstream/main

return true;
}
Expand Down
30 changes: 20 additions & 10 deletions Router/ARPLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public class ARPLayer implements BaseLayer{
public BaseLayer p_UnderLayer = null;
public ArrayList<BaseLayer> p_aUpperLayer = new ArrayList<BaseLayer>();
public Hashtable<String,Timer> timerList = new Hashtable<>();


public String interfaceName;
// TODO Get interfaceName

byte[] BROADCAST = broadcast();

// GUI Layer 변수
Expand Down Expand Up @@ -156,15 +159,21 @@ public boolean isStatus() {
public void setStatus(boolean status) {
this.status = status;
}


public void setInterfaceName(String interfaceName) { this.interfaceName = interfaceName; }

public String getInterfaceName() { return interfaceName; }

byte[] ipAddr;
byte[] macAddr;
boolean status; // complete == true, incomplete == false

public _ARP_Cache(byte[] ipAddr, byte[] macAddr, boolean status) {
String interfaceName;

public _ARP_Cache(byte[] ipAddr, byte[] macAddr, boolean status, String interfaceName) {
this.ipAddr = ipAddr;
this.macAddr = macAddr;
this.status = status;
this.interfaceName = interfaceName;
}
}

Expand Down Expand Up @@ -201,7 +210,7 @@ public boolean Send(byte[] input, int length) {
System.out.println("ARP Cache Table에 없는 IP주소로 전송 시작");
((EthernetLayer)this.GetUnderLayer()).set_dstaddr(BROADCAST); //Broadcast로 목적지 설정
byte[] TargetMac = new byte[6];
_ARP_Cache cache = new _ARP_Cache(dstIPAddress, TargetMac, false);
_ARP_Cache cache = new _ARP_Cache(dstIPAddress, TargetMac, false, interfaceName);
ArpCacheTable.add(cache);
// 모르는 주소이므로 3분으로 타이머 설정
Timer timer = this.setTimeOut(dstIPAddress, 3 * 60 * 1000);
Expand Down Expand Up @@ -277,7 +286,7 @@ else if(IsMyIP(TargetIP) || IsInProxyTable(TargetIP)) {
ReplySend(input);
}
}
UpdateARPCache(SenderIP, SenderMac, true);
UpdateARPCache(SenderIP, SenderMac, true, interfaceName);
GUI_LAYER.GetArpTable(); // ARP Table 업데이트

return true;
Expand Down Expand Up @@ -380,8 +389,8 @@ public boolean IsIPEquals(byte[] ip1, byte[] ip2) {
}

// ARP Cache Table 추가하는 함수
public boolean AddARPCache(byte[] IPAddr, byte[] MACAddr, boolean status) {
_ARP_Cache newArpCache = new _ARP_Cache(IPAddr, MACAddr, status);
public boolean AddARPCache(byte[] IPAddr, byte[] MACAddr, boolean status, String interfaceName) {
_ARP_Cache newArpCache = new _ARP_Cache(IPAddr, MACAddr, status, interfaceName);
ArpCacheTable.add(newArpCache);
return true;
}
Expand All @@ -401,15 +410,16 @@ public boolean RemoveARPCache(byte[] IPAddr) {
return false;
}
// ARP Cache Table 업데이트 하는 함수
public boolean UpdateARPCache(byte[] IPAddr, byte[] MACAddr, boolean status) {
public boolean UpdateARPCache(byte[] IPAddr, byte[] MACAddr, boolean status, String interfaceName) {
// iterator로 ArrayList를 순회
int idx = IsInArpCacheTable(IPAddr);
if(idx >= 0){
ArpCacheTable.get(idx).setIpAddr(IPAddr);
ArpCacheTable.get(idx).setMacAddr(MACAddr);
ArpCacheTable.get(idx).setStatus(status);
AroCacheTable.get(idx).setInterfaceName(interfaceName);
} else {
ArpCacheTable.add(new _ARP_Cache(IPAddr, MACAddr, status));
ArpCacheTable.add(new _ARP_Cache(IPAddr, MACAddr, status, interfaceName));
}

return false;
Expand Down