es.tid.pce.pcep.objects.PceIdIPv4 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of network-protocols Show documentation
Show all versions of network-protocols Show documentation
BGP-LS,OSPF-TE,PCEP and RSVP-TE protocol encodings.
The newest version!
package es.tid.pce.pcep.objects;
import java.net.Inet4Address;
import java.net.UnknownHostException;
public class PceIdIPv4 extends PceId {
/**
* PCE IPv4 address
*/
private Inet4Address pceIPAddress;
public PceIdIPv4(){
super();
this.setObjectClass(ObjectParameters.PCEP_OBJECT_CLASS_PCE_ID);
this.setOT(ObjectParameters.PCEP_OBJECT_TYPE_PCE_ID_IPV4);
}
public PceIdIPv4(byte []bytes, int offset)throws MalformedPCEPObjectException {
super(bytes,offset);
decode();
}
@Override
public void encode() {
this.ObjectLength=8;
this.object_bytes=new byte[ObjectLength];
encode_header();
System.arraycopy(pceIPAddress.getAddress(),0, this.object_bytes, 4, 4);
}
@Override
public void decode() throws MalformedPCEPObjectException {
if (this.ObjectLength!=8){
throw new MalformedPCEPObjectException();
}
byte[] ip=new byte[4];
System.arraycopy(this.object_bytes,4, ip, 0, 4);
try {
pceIPAddress=(Inet4Address)Inet4Address.getByAddress(ip);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Inet4Address getPceIPAddress() {
return pceIPAddress;
}
public void setPceIPAddress(Inet4Address pceIPAddress) {
this.pceIPAddress = pceIPAddress;
}
public String toString(){
String ret="";
}else {
ret+=">";
}
return ret;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result
+ ((pceIPAddress == null) ? 0 : pceIPAddress.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
PceIdIPv4 other = (PceIdIPv4) obj;
if (pceIPAddress == null) {
if (other.pceIPAddress != null)
return false;
} else if (!pceIPAddress.equals(other.pceIPAddress))
return false;
return true;
}
}