Added support for gateway configuration files
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
index 30491a9..486d057 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
@@ -1,5 +1,6 @@
 package net.onrc.onos.ofcontroller.bgproute;
 
+import java.io.File;
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -23,18 +24,19 @@
 import net.floodlightcontroller.restserver.IRestApiService;
 import net.floodlightcontroller.topology.ITopologyListener;
 import net.floodlightcontroller.topology.ITopologyService;
-import net.floodlightcontroller.util.MACAddress;
 import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoRouteService;
 import net.onrc.onos.ofcontroller.util.DataPath;
-import net.onrc.onos.ofcontroller.util.Dpid;
 import net.onrc.onos.ofcontroller.util.FlowEntry;
-import net.onrc.onos.ofcontroller.util.IPv4;
 import net.onrc.onos.ofcontroller.util.Port;
 import net.onrc.onos.ofcontroller.util.SwitchPort;
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
 import net.sf.json.JSONSerializer;
 
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.type.TypeReference;
 import org.openflow.protocol.OFFlowMod;
 import org.openflow.protocol.OFMatch;
 import org.openflow.protocol.OFMessage;
@@ -61,6 +63,7 @@
 	protected static Ptree ptree;
 	protected String bgpdRestIp;
 	protected String routerId;
+	protected String gatewaysFilename = "gateways.json";
 	
 	protected Set<InetAddress> routerIpAddresses;
 	
@@ -75,43 +78,27 @@
 	//need to be higher priority than this otherwise the rewrite may not get done
 	protected final short SDNIP_PRIORITY = 10;
 	
-	//TODO temporary
-	protected List<GatewayRouter> gatewayRouters;
+	protected Map<String, GatewayRouter> gatewayRouters;
 	
-	private void initGateways(){
-		gatewayRouters = new ArrayList<GatewayRouter>();
-		//00:00:00:00:00:00:0s0:a3 port 1
-		gatewayRouters.add(
-				new GatewayRouter(new SwitchPort(new Dpid(163L), new Port((short)1)),
-				new MACAddress(new byte[] {0x00, 0x00, 0x00, 0x00, 0x02, 0x01}),
-				new IPv4("192.168.10.1"),
-				new MACAddress(new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x01}),
-				new IPv4("192.168.10.101")));
-		//00:00:00:00:00:00:00:a5 port 1
-		//gatewayRouters.add(new SwitchPort(new Dpid(165L), new Port((short)1)));
-		gatewayRouters.add(
-				new GatewayRouter(new SwitchPort(new Dpid(165L), new Port((short)1)),
-				new MACAddress(new byte[] {0x00, 0x00, 0x00, 0x00, 0x02, 0x02}),
-				new IPv4("192.168.20.1"),
-				new MACAddress(new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x02}),
-				new IPv4("192.168.20.101")));
-		//00:00:00:00:00:00:00:a2 port 1
-		//gatewayRouters.add(new SwitchPort(new Dpid(162L), new Port((short)1)));
-		gatewayRouters.add(
-				new GatewayRouter(new SwitchPort(new Dpid(162L), new Port((short)1)),
-				new MACAddress(new byte[] {0x00, 0x00, 0x00, 0x00, 0x03, 0x01}),
-				new IPv4("192.168.30.1"),
-				new MACAddress(new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}),
-				new IPv4("192.168.30.101")));
-		//00:00:00:00:00:00:00:a6
-		//gatewayRouters.add(new SwitchPort(new Dpid(166L), new Port((short)1)));
-		gatewayRouters.add(
-				new GatewayRouter(new SwitchPort(new Dpid(166L), new Port((short)1)),
-				new MACAddress(new byte[] {0x00, 0x00, 0x00, 0x00, 0x04, 0x01}),
-				new IPv4("192.168.40.1"),
-				new MACAddress(new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x04}),
-				new IPv4("192.168.40.101")));
+	private void readGatewaysConfiguration(String gatewaysFilename){
+		File gatewaysFile = new File(gatewaysFilename);
+		ObjectMapper mapper = new ObjectMapper();
 		
+		TypeReference<HashMap<String, GatewayRouter>> typeref 
+			= new TypeReference<HashMap<String, GatewayRouter>>() {};
+		
+		try {
+			gatewayRouters = mapper.readValue(gatewaysFile, typeref);
+		} catch (JsonParseException e) {
+			log.error("Error in JSON file", e);
+			System.exit(1);
+		} catch (JsonMappingException e) {
+			log.error("Error in JSON file", e);
+			System.exit(1);
+		} catch (IOException e) {
+			log.error("Error reading JSON file", e);
+			System.exit(1);
+		}
 	}
 	
 	@Override
@@ -146,8 +133,6 @@
 	public void init(FloodlightModuleContext context)
 			throws FloodlightModuleException {
 	    
-		initGateways();
-		
 	    ptree = new Ptree(32);
 	    
 	    routerIpAddresses = new HashSet<InetAddress>();
@@ -177,6 +162,8 @@
 		else {
 			log.info("RouterId set to {}", routerId);
 		}
+		
+		readGatewaysConfiguration(gatewaysFilename);
 		// Test.
 		//test();
 	}
@@ -332,14 +319,8 @@
 	
 	public void prefixAdded(PtreeNode node) {
 		//Add a flow to rewrite mac for this prefix to all border switches
-		GatewayRouter thisRouter = null;
-		for (GatewayRouter router : gatewayRouters){	
-			if (router.getRouterIp().value() == 
-					InetAddresses.coerceToInteger(node.rib.nextHop)){
-				thisRouter = router;
-				break;
-			}
-		}
+		GatewayRouter thisRouter = gatewayRouters
+				.get(InetAddresses.toAddrString(node.rib.nextHop));
 		
 		if (thisRouter == null){
 			//TODO local router isn't in gateway list so this will get thrown
@@ -349,7 +330,7 @@
 			return; //just quit out here? This is probably a configuration error
 		}
 
-		for (GatewayRouter ingressRouter : gatewayRouters){
+		for (GatewayRouter ingressRouter : gatewayRouters.values()){
 			if (ingressRouter == thisRouter) {
 				continue;
 			}
@@ -457,8 +438,7 @@
 		
 		//have to account for switches not being there, paths not being found.
 		
-		//for (SwitchPort switchPort : gatewayRouters){
-		for (GatewayRouter router : gatewayRouters){
+		for (GatewayRouter router : gatewayRouters.values()){
 			SwitchPort switchPort = router.getAttachmentPoint();
 			
 			IOFSwitch sw = floodlightProvider.getSwitches().get(switchPort.dpid().value());
@@ -483,7 +463,7 @@
 		//for each prefix received. This will be done later when prefixes have 
 		//actually been received.
 		
-		for (GatewayRouter dstRouter : gatewayRouters){
+		for (GatewayRouter dstRouter : gatewayRouters.values()){
 			SwitchPort routerAttachmentPoint = dstRouter.getAttachmentPoint();
 			for (Map.Entry<IOFSwitch, SwitchPort> src : gatewaySwitches.entrySet()) {
 		
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/GatewayRouter.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/GatewayRouter.java
index 4c4728f..4016c69 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/bgproute/GatewayRouter.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/bgproute/GatewayRouter.java
@@ -1,46 +1,62 @@
 package net.onrc.onos.ofcontroller.bgproute;
 
 import net.floodlightcontroller.util.MACAddress;
+import net.onrc.onos.ofcontroller.util.Dpid;
 import net.onrc.onos.ofcontroller.util.IPv4;
+import net.onrc.onos.ofcontroller.util.Port;
 import net.onrc.onos.ofcontroller.util.SwitchPort;
 
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.openflow.util.HexString;
+
 public class GatewayRouter {
-	private SwitchPort attachmentPoint;
+	private SwitchPort attachmentPoint = null;
+	private long dpid;
+	private short port;
 	private MACAddress routerMac;
 	private IPv4 routerIp;
 	
-	//For now, put in the IP and MAC of the SDN domain's router that this 
-	//gateway will be communicating with
-	private MACAddress sdnRouterMac;
-	private IPv4 sdnRouterIp;
 	
-	public GatewayRouter(SwitchPort attachmentPoint, MACAddress routerMac, 
-			IPv4 routerIp, MACAddress sdnRouterMac, IPv4 sdnRouterIp) {
-		this.attachmentPoint = attachmentPoint;
-		this.routerMac = routerMac;
-		this.routerIp = routerIp;
-		this.sdnRouterIp = sdnRouterIp;
-		this.sdnRouterMac = sdnRouterMac;
+	public SwitchPort getAttachmentPoint() {
+		if (attachmentPoint == null){
+			attachmentPoint = new SwitchPort(new Dpid(dpid), new Port(port));
+		}
+		return attachmentPoint;
+	}
+	
+	public long getDpid() {
+		return dpid;
 	}
 
-	public SwitchPort getAttachmentPoint() {
-		return attachmentPoint;
+	@JsonProperty("attachmentDpid")
+	public void setDpid(String dpid) {
+		this.dpid = HexString.toLong(dpid);
+	}
+
+	public short getPort() {
+		return port;
+	}
+
+	@JsonProperty("attachmentPort")
+	public void setPort(short port) {
+		this.port = port;
 	}
 
 	public MACAddress getRouterMac() {
 		return routerMac;
 	}
+	
+	@JsonProperty("macAddress")
+	public void setRouterMac(String routerMac) {
+		this.routerMac = MACAddress.valueOf(routerMac);;
+	}
 
 	public IPv4 getRouterIp() {
 		return routerIp;
 	}
 	
-	//TODO delete if not needed
-	public MACAddress getSdnRouterMac() {
-		return sdnRouterMac;
-	}
-	
-	public IPv4 getSdnRouterIp() {
-		return sdnRouterIp;
+	@JsonProperty("ipAddress")
+	public void setRouterIp(String routerIp) {
+		this.routerIp = new IPv4(routerIp);
 	}
 }
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowcache/FlowManager.java b/src/main/java/net/onrc/onos/ofcontroller/flowcache/FlowManager.java
index 355ce8e..9c38cdd 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowcache/FlowManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowcache/FlowManager.java
@@ -500,9 +500,9 @@
 		nextFlowEntryIdPrefix = randomGenerator.nextInt();
 		
 		mapReaderScheduler.scheduleAtFixedRate(
-				mapReader, 1, 1, TimeUnit.SECONDS);
+				mapReader, 3, 3, TimeUnit.SECONDS);
 		shortestPathReconcileScheduler.scheduleAtFixedRate(
-				shortestPathReconcile, 100, 100, TimeUnit.MILLISECONDS);
+				shortestPathReconcile, 3, 3, TimeUnit.SECONDS);
     }
 
     /**