package org.kne.cloud.network.ipv6;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;

public class PacketIDGenerator {
	private UUID flowuuid;
	private AtomicLong sequence;
	public PacketIDGenerator() {
		flowuuid=UUID.randomUUID();
		sequence=new AtomicLong();
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((flowuuid == null) ? 0 : flowuuid.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PacketIDGenerator other = (PacketIDGenerator) obj;
		if (flowuuid == null) {
			if (other.flowuuid != null)
				return false;
		} else if (!flowuuid.equals(other.flowuuid))
			return false;
		return true;
	}
	public PacketIDGenerator(UUID flowuuid, AtomicLong sequence) {
		super();
		this.flowuuid = flowuuid;
		this.sequence = sequence;
	}
	public UUID getFlowuuid() {
		return flowuuid;
	}
	public AtomicLong getSequence() {
		return sequence;
	}
	@Override
	public String toString() {
		return "PacketIDGenerater [flowuuid=" + flowuuid + ", sequence=" + sequence + "]";
	}
	
	public PacketID generate() {
		return new PacketID(flowuuid, sequence.getAndIncrement());
	}
}
