use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method cancelClientDhcpPacket.
private void cancelClientDhcpPacket(Ip6Address serverIp) {
// Packet comes from relay
TrafficSelector indirectClientSelector = DefaultTrafficSelector.builder(SERVER_RELAY_SELECTOR).matchIPv6Dst(serverIp.toIpPrefix()).build();
packetService.cancelPackets(indirectClientSelector, PacketPriority.CONTROL, appId);
indirectClientSelector = DefaultTrafficSelector.builder(SERVER_RELAY_SELECTOR).matchIPv6Dst(Ip6Address.ALL_DHCP_RELAY_AGENTS_AND_SERVERS.toIpPrefix()).build();
packetService.cancelPackets(indirectClientSelector, PacketPriority.CONTROL, appId);
indirectClientSelector = DefaultTrafficSelector.builder(SERVER_RELAY_SELECTOR).matchIPv6Dst(Ip6Address.ALL_DHCP_SERVERS.toIpPrefix()).build();
packetService.cancelPackets(indirectClientSelector, PacketPriority.CONTROL, appId);
// Packet comes from client
packetService.cancelPackets(CLIENT_SERVER_SELECTOR, PacketPriority.CONTROL, appId);
}
use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method cancelServerDhcpPacket.
private void cancelServerDhcpPacket(Ip6Address serverIp) {
TrafficSelector serverSelector = DefaultTrafficSelector.builder(SERVER_RELAY_SELECTOR).matchIPv6Src(serverIp.toIpPrefix()).build();
packetService.cancelPackets(serverSelector, PacketPriority.CONTROL, appId);
}
use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class PortWaveLengthCommand method doExecute.
@Override
protected void doExecute() throws Exception {
if (operation.equals("edit-config") || operation.equals("delete-config")) {
FlowRuleService flowService = get(FlowRuleService.class);
DeviceService deviceService = get(DeviceService.class);
CoreService coreService = get(CoreService.class);
TrafficSelector.Builder trafficSelectorBuilder = DefaultTrafficSelector.builder();
TrafficTreatment.Builder trafficTreatmentBuilder = DefaultTrafficTreatment.builder();
FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
ConnectPoint inCp, outCp = null;
Device inDevice, outDevice = null;
inCp = ConnectPoint.deviceConnectPoint(inConnectPointString);
inDevice = deviceService.getDevice(inCp.deviceId());
if (outConnectPointString != null) {
outCp = ConnectPoint.deviceConnectPoint(outConnectPointString);
outDevice = deviceService.getDevice(outCp.deviceId());
}
if (inDevice.type().equals(Device.Type.TERMINAL_DEVICE)) {
// Parsing the ochSignal
OchSignal ochSignal;
if (parameter.contains("/")) {
ochSignal = createOchSignal();
} else if (parameter.matches("-?\\d+(\\.\\d+)?")) {
ochSignal = createOchSignalFromWavelength(deviceService, inCp);
} else {
print("[ERROR] signal or wavelength %s are in uncorrect format");
return;
}
if (ochSignal == null) {
print("[ERROR] problem while creating OchSignal");
return;
}
// Traffic selector
TrafficSelector trafficSelector = trafficSelectorBuilder.matchInPort(inCp.port()).build();
// Traffic treatment including ochSignal
TrafficTreatment trafficTreatment = trafficTreatmentBuilder.add(Instructions.modL0Lambda(ochSignal)).add(Instructions.createOutput(deviceService.getPort(inCp).number())).build();
int priority = 100;
ApplicationId appId = coreService.registerApplication("org.onosproject.optical-model");
// Flow rule using selector and treatment
FlowRule addFlow = flowRuleBuilder.withPriority(priority).fromApp(appId).withTreatment(trafficTreatment).withSelector(trafficSelector).forDevice(inDevice.id()).makePermanent().build();
// Print output on CLI
if (operation.equals("edit-config")) {
flowService.applyFlowRules(addFlow);
print("[INFO] Setting ochSignal on TERMINAL_DEVICE %s", ochSignal);
print("--- device: %s", inDevice.id());
print("--- port: %s", inCp.port());
print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
} else {
// This is delete-config
flowService.removeFlowRules(addFlow);
print("[INFO] Deleting ochSignal on TERMINAL_DEVICE %s", ochSignal);
print("--- device: %s", inDevice.id());
print("--- port: %s", inCp.port());
print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
}
}
if (inDevice.type().equals(Device.Type.ROADM)) {
if (outConnectPointString == null) {
print("[ERROR] output port is required for ROADM devices");
return;
}
if (!inDevice.equals(outDevice)) {
print("[ERROR] input and output ports must be on the same device");
return;
}
// Parsing the ochSignal
OchSignal ochSignal;
if (parameter.contains("/")) {
ochSignal = createOchSignal();
} else if (parameter.matches("-?\\d+(\\.\\d+)?")) {
ochSignal = createOchSignalFromWavelength(deviceService, inCp);
} else {
print("[ERROR] signal or wavelength %s are in uncorrect format");
return;
}
if (ochSignal == null) {
print("[ERROR] problem while creating OchSignal");
return;
}
// Traffic selector
TrafficSelector trafficSelector = trafficSelectorBuilder.matchInPort(inCp.port()).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(ochSignal)).build();
// Traffic treatment
TrafficTreatment trafficTreatment = trafficTreatmentBuilder.add(Instructions.modL0Lambda(ochSignal)).add(Instructions.createOutput(deviceService.getPort(outCp).number())).build();
int priority = 100;
ApplicationId appId = coreService.registerApplication("org.onosproject.optical-model");
// Flow rule using selector and treatment
FlowRule addFlow = flowRuleBuilder.withPriority(priority).fromApp(appId).withTreatment(trafficTreatment).withSelector(trafficSelector).forDevice(inDevice.id()).makePermanent().build();
// Print output on CLI
if (operation.equals("edit-config")) {
flowService.applyFlowRules(addFlow);
print("[INFO] Setting ochSignal on ROADM %s", ochSignal);
print("--- device: %s", inDevice.id());
print("--- input port %s, outpot port %s", inCp.port(), outCp.port());
print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
print("--- frequency slot width (GHz): %s", ochSignal.slotGranularity() * 12.5);
} else {
// This is delete-config
flowService.removeFlowRules(addFlow);
print("[INFO] Deleting ochSignal on ROADM %s", ochSignal);
print("--- device: %s", inDevice.id());
print("--- input port %s, outpot port %s", inCp.port(), outCp.port());
print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
print("--- frequency slot width (GHz): %s", ochSignal.slotGranularity() * 12.5);
}
}
if (!inDevice.type().equals(Device.Type.ROADM) && !inDevice.type().equals(Device.Type.TERMINAL_DEVICE)) {
print("[ERROR] wrong device type: %s", inDevice.type());
}
} else {
print("[ERROR] operation %s is not yet supported", operation);
}
}
use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class OpenstackTroubleshootManager method setVidTagRule.
/**
* Installs/uninstalls a flow rule to match ingress fake ICMP request packets,
* and tags VNI/VID, direct the tagged packet to ACL table.
*
* @param port instance port
* @param install installation flag
*/
private void setVidTagRule(InstancePort port, boolean install) {
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(port.ipAddress(), PREFIX_LENGTH)).build();
TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder().setTunnelId(getSegId(osNetworkService, port)).transition(ACL_EGRESS_TABLE);
osFlowRuleService.setRule(appId, port.deviceId(), selector, tb.build(), PRIORITY_ICMP_PROBE_RULE, VTAG_TABLE, install);
}
use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class OpenstackTroubleshootManager method checkFlowRule.
/**
* Checks whether flow rules with the given IP and criterion are added or not.
*
* @param ip IP address
* @param ipType IP criterion type (IPV4_DST or IPV4_SRC)
* @return true if the flow rule is added, false otherwise
*/
private boolean checkFlowRule(String ip, Criterion.Type ipType) {
for (FlowEntry entry : flowRuleService.getFlowEntriesById(appId)) {
TrafficSelector selector = entry.selector();
IPCriterion ipCriterion = (IPCriterion) selector.getCriterion(ipType);
if (ipCriterion != null && ip.equals(ipCriterion.ip().address().toString()) && entry.state() == ADDED) {
return true;
}
}
return false;
}
Aggregations