FlowscaleController.logger.trace("in ruleset pushing rules now: ");
FlowscaleController.logger.trace("group rules are {} ", groupRules);
// handle output switch first
IOFSwitch outputSwitch = flowscaleController.getIBeaconProvider()
.getSwitches().get(outputSwitchDatapathId);
OFFlowMod flowModRule = new OFFlowMod();
flowModRule.setType(OFType.FLOW_MOD);
flowModRule.setCommand(OFFlowMod.OFPFC_ADD);
flowModRule.setHardTimeout((short) 0);
flowModRule.setIdleTimeout((short) 0);
flowModRule.setBufferId(-1);
int count = 0;
int actionOutputLength;
if (this.dropPortGroup) {
actionOutputLength = 0;
} else {
actionOutputLength = OFActionOutput.MINIMUM_LENGTH;
}
for (OFRule rule : this.groupRules) {
count++;
flowModRule.setMatch(rule.getMatch());
if (!this.dropPortGroup) {
// add mirroring capabitlites
HashMap<Short, Short> switchMirrors = flowscaleController
.getSwitchFlowMirrorPortsHashMap().get(
outputSwitch.getId());
if (switchMirrors != null) {
FlowscaleController.logger.debug("Mirror hashmap {}",
switchMirrors.toString());
OFActionOutput actionPort = null;
try {
FlowscaleController.logger.debug("Mirror actions = {}",
rule.getActions());
if (rule.getActions() != null) {
actionPort = ((OFActionOutput) rule.getActions()
.get(0));
FlowscaleController.logger.debug(
"Action port for Mirror is {}",
actionPort.getPort());
}
Short mirrorPortValue = switchMirrors.get(actionPort
.getPort());
if (mirrorPortValue != null) {
FlowscaleController.logger
.debug("mirror {} for switch {} set ",
actionPort.getPort()
+ ","
+ mirrorPortValue
.toString(),
HexString.toHexString(outputSwitch
.getId()));
rule.setMirrorPort(mirrorPortValue);
}
} catch (NumberFormatException nfe) {
FlowscaleController.logger.error(
"OFAction {} is not directed to a switch port",
flowModRule.getActions().get(0).toString());
}
}
// after checking mirrors set actions
flowModRule.setActions(rule.getActions());
}
flowModRule.setLength(U16.t(OFFlowMod.MINIMUM_LENGTH
+ actionOutputLength));
flowModRule.setPriority(rule.getPriority());
try {
FlowscaleController.logger.debug("{}", flowModRule);
outputSwitch.getOutputStream().write(flowModRule);
if (count >= flowscaleController.getMaximumFlowsToPush()) {
count = 0;
outputSwitch.getOutputStream().flush();
Thread.sleep(5000);
}
} catch (InterruptedException interruptedException) {
FlowscaleController.logger.error("{}", interruptedException);
} catch (IOException e) {
// TODO Auto-generated catch block
FlowscaleController.logger.error("{}", e);
}
}
try {
outputSwitch.getOutputStream().flush();
} catch (Exception e) {
FlowscaleController.logger.error("{}", e);
}