package org.kne.cloud.network.srv6;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import java.net.Inet6Address;
import java.util.Objects;

import org.kne.cloud.network.ipv6.IPv6AddressGroup;
import org.kne.cloud.network.ipv6.Neighbor;

public class NeighborInfo implements Serializable {
	@Override
	public String toString() {
		return "NeighborInfo [local=" + local + ", neighbor=" + neighbor + ", locator=" + locator + ", uploadDelay="
				+ uploadDelay + ", downloadDelay=" + downloadDelay + ", uploadSpeed=" + uploadSpeed + ", downloadSpeed="
				+ downloadSpeed + ", uploadSpeedMax=" + uploadSpeedMax + ", downloadSpeedMax=" + downloadSpeedMax + "]";
	}
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private IPv6AddressGroup local;
	private IPv6AddressGroup neighbor;
	private IPv6AddressGroup locator;
	private transient Neighbor context;
	public NeighborInfo(IPv6AddressGroup local,IPv6AddressGroup neighbor,IPv6AddressGroup locator, long uploadDelay, long downloadDelay,long uploadDelayMin, long downloadDelayMin, long uploadSpeed, long downloadSpeed, long uploadspeedmax, long downloadspeedmax) {
		super();
		this.local=local;
		this.neighbor = neighbor;
		this.locator=locator;
		this.uploadDelay = uploadDelay;
		this.downloadDelay = downloadDelay;
		this.uploadDelayMin = uploadDelayMin;
		this.downloadDelayMin= downloadDelayMin;
		this.uploadSpeed = uploadSpeed;
		this.downloadSpeed = downloadSpeed;
		this.uploadSpeedMax=uploadspeedmax;
		this.downloadSpeedMax=downloadspeedmax;
	}
	public NeighborInfo() {
	}
	
	private long uploadDelay;
	private long downloadDelay;
	private long uploadDelayMin;
	private long downloadDelayMin;
	private long uploadSpeed;
	private long downloadSpeed;
	private long uploadSpeedMax;
	private long downloadSpeedMax;
	
	
	
	public void setContext(Neighbor context) {
		this.context = context;
	}
	public Neighbor getContext() {
		return context;
	}
	public IPv6AddressGroup getNeighbor() {
		return neighbor;
	}
	public void setNeighbor(IPv6AddressGroup neighbor) {
		this.neighbor = neighbor;
	}
	public long getUploadDelay() {
		return uploadDelay;
	}
	public void setUploadDelay(long uploadDelay) {
		this.uploadDelay = uploadDelay;
	}
	public long getDownloadDelay() {
		return downloadDelay;
	}
	public void setDownloadDelay(long downloadDelay) {
		this.downloadDelay = downloadDelay;
	}
	public long getUploadSpeed() {
		return uploadSpeed;
	}
	public void setUploadSpeed(long uploadSpeed) {
		this.uploadSpeed = uploadSpeed;
	}
	public long getDownloadSpeed() {
		return downloadSpeed;
	}
	public long getUploadSpeedMax() {
		return uploadSpeedMax;
	}
	public void setUploadSpeedMax(long uploadSpeedMax) {
		this.uploadSpeedMax = uploadSpeedMax;
	}
	public long getDownloadSpeedMax() {
		return downloadSpeedMax;
	}
	public void setDownloadSpeedMax(long downloadSpeedMax) {
		this.downloadSpeedMax = downloadSpeedMax;
	}
	public void setDownloadSpeed(long downloadSpeed) {
		this.downloadSpeed = downloadSpeed;
	}
	public IPv6AddressGroup getLocal() {
		return local;
	}
	public void setLocal(IPv6AddressGroup local) {
		this.local = local;
	}
	public IPv6AddressGroup getLocator() {
		return locator;
	}
	public void setLocator(IPv6AddressGroup locator) {
		this.locator = locator;
	}
	
	@Override
	public int hashCode() {
		return Objects.hash(local, locator, neighbor);
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		NeighborInfo other = (NeighborInfo) obj;
		return Objects.equals(local, other.local) && Objects.equals(locator, other.locator)
				&& Objects.equals(neighbor, other.neighbor);
	}
	public void writeToStream(DataOutputStream out) throws IOException {
		local.writeToStream(out);
		neighbor.writeToStream(out);
		locator.writeToStream(out);
		out.writeLong(uploadDelay);
		out.writeLong(downloadDelay);
		out.writeLong(uploadDelayMin);
		out.writeLong(downloadDelayMin);
		out.writeLong(uploadSpeed);
		out.writeLong(downloadSpeed);
		out.writeLong(uploadSpeedMax);
		out.writeLong(downloadSpeedMax);
	}
	
	public void readFromStream(DataInputStream in) throws IOException {
		local=new IPv6AddressGroup(in);
		neighbor=new IPv6AddressGroup( in);
		locator=new IPv6AddressGroup(in);
		uploadDelay=in.readLong();
		downloadDelay=in.readLong();
		uploadDelayMin=in.readLong();
		downloadDelayMin=in.readLong();
		uploadSpeed=in.readLong();
		downloadSpeed=in.readLong();
		uploadSpeedMax=in.readLong();
		downloadSpeedMax=in.readLong();
	}
	public long getUploadDelayMin() {
		return uploadDelayMin;
	}
	public long getDownloadDelayMin() {
		return downloadDelayMin;
	}
}
