/** * Sets the flow rules for traffic between VMs in the same Cnode. * * @param ip4Address VM IP address * @param id device ID to put rules * @param port VM port * @param vni VM VNI */ private void setFlowRuleForVMsInSameCnode(Ip4Address ip4Address, DeviceId id, Port port, String vni) { //For L2 Switching Case TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); sBuilder.matchEthType(Ethernet.TYPE_IPV4) .matchIPDst(ip4Address.toIpPrefix()) .matchTunnelId(Long.parseLong(vni)); tBuilder.setOutput(port.number()); ForwardingObjective fo = DefaultForwardingObjective.builder() .withSelector(sBuilder.build()) .withTreatment(tBuilder.build()) .withPriority(SWITCHING_RULE_PRIORITY) .withFlag(ForwardingObjective.Flag.SPECIFIC) .fromApp(appId) .add(); flowObjectiveService.forward(id, fo); }
/** * Sets the flow rules between traffic from VMs in different Cnode. * * @param vni VNI * @param deviceId device ID * @param hostIp host IP of the VM * @param vmIp fixed IP of the VM */ private void setVxLanFlowRule(String vni, DeviceId deviceId, Ip4Address hostIp, Ip4Address vmIp) { TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); sBuilder.matchEthType(Ethernet.TYPE_IPV4) .matchTunnelId(Long.parseLong(vni)) .matchIPDst(vmIp.toIpPrefix()); tBuilder.extension(buildNiciraExtenstion(deviceId, hostIp), deviceId) .setOutput(getTunnelPort(deviceId)); ForwardingObjective fo = DefaultForwardingObjective.builder() .withSelector(sBuilder.build()) .withTreatment(tBuilder.build()) .withPriority(SWITCHING_RULE_PRIORITY) .withFlag(ForwardingObjective.Flag.SPECIFIC) .fromApp(appId) .add(); flowObjectiveService.forward(deviceId, fo); }
/** * Removes the flow rules between traffic from VMs in different Cnode. * * @param deviceId device id * @param vmIp ip * @param vni vni which removed VM was belonged */ private void removeVxLanFlowRule(DeviceId deviceId, Ip4Address vmIp, long vni) { TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); sBuilder.matchEthType(Ethernet.TYPE_IPV4) .matchTunnelId(vni) .matchIPDst(vmIp.toIpPrefix()); ForwardingObjective fo = DefaultForwardingObjective.builder() .withSelector(sBuilder.build()) .withTreatment(DefaultTrafficTreatment.builder().build()) .withFlag(ForwardingObjective.Flag.SPECIFIC) .withPriority(SWITCHING_RULE_PRIORITY) .fromApp(appId) .remove(); flowObjectiveService.forward(deviceId, fo); }
/** * Removes the flow rules for traffic between VMs in the same Cnode. * * @param deviceId device id on which removed VM was run * @param vmIp ip of the removed VM * @param vni vni which removed VM was belonged */ private void removeFlowRuleForVMsInSameCnode(DeviceId deviceId, Ip4Address vmIp, long vni) { TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); sBuilder.matchEthType(Ethernet.TYPE_IPV4) .matchIPDst(vmIp.toIpPrefix()) .matchTunnelId(vni); ForwardingObjective fo = DefaultForwardingObjective.builder() .withSelector(sBuilder.build()) .withTreatment(DefaultTrafficTreatment.builder().build()) .withFlag(ForwardingObjective.Flag.SPECIFIC) .withPriority(SWITCHING_RULE_PRIORITY) .fromApp(appId) .remove(); flowObjectiveService.forward(deviceId, fo); }