* @param datapathId
* id of concerned switch that we desire to hotswap flows
*/
public void injectFlows(ArrayList<OFFlowMod> ofFlowMods, long datapathId) {
logger.info("injecting flows in controller");
IOFSwitch sw = this.ibeaconProvider.getSwitches().get(datapathId);
if (sw == null) {
logger.error("no switch {} exists", datapathId);
return;
}
for (OFFlowMod ofFlowMod : ofFlowMods) {
logger.info("injecting flow {}", ofFlowMod);
for (Integer groupKey : groupList.keySet()) {
Group group = groupList.get(groupKey);
ArrayList<OFRule> groupRules = (ArrayList<OFRule>) group
.getGroupRules();
for (OFRule rule : groupRules) {
if (rule.getMatch().equals(ofFlowMod.getMatch())
&& group.getOutputSwitchDatapathId() == datapathId) {
logger.info("rule equal", rule.getMatch().toString(),
ofFlowMod.getMatch().toString());
ofFlowMod.setPriority(rule.getPriority());
ArrayList<OFAction> aList = rule.getActions();
aList.clear();
short port = ((OFActionOutput) ofFlowMod.getActions()
.get(0)).getPort();
rule.setPort(port);
Short mirrorPort = 0;
if (switchFlowMirrorPortsHashMap.get(datapathId) != null) {
mirrorPort = switchFlowMirrorPortsHashMap.get(
datapathId).get(port);
}
if (mirrorPort != null) {
rule.setMirrorPort(mirrorPort);
}
logger.info("new rule is {} and port is {}",
rule.getMatch(), rule.getActions().get(0));
}
}
}
try {
sw.getOutputStream().write(ofFlowMod);
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("{}", e);
}
}
try {
sw.getOutputStream().flush();
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("{}", e);
}