use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class K8sFlowRuleManager method setAnyRoutingRule.
private void setAnyRoutingRule(IpPrefix srcIpPrefix, MacAddress mac, K8sNetwork k8sNetwork) {
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(srcIpPrefix).matchIPDst(IpPrefix.valueOf(k8sNetwork.cidr()));
for (K8sNode node : k8sNodeService.completeNodes()) {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setTunnelId(Long.valueOf(k8sNetwork.segmentId()));
if (node.hostname().equals(k8sNetwork.name())) {
if (mac != null) {
tBuilder.setEthSrc(mac);
}
tBuilder.transition(STAT_EGRESS_TABLE);
} else {
K8sNode localNode = k8sNodeService.node(k8sNetwork.name());
tBuilder.setOutput(node.intgToTunPortNum());
// install flows into tunnel bridge
PortNumber portNum = tunnelPortNumByNetId(k8sNetwork.networkId(), k8sNetworkService, node);
TrafficTreatment treatmentToRemote = DefaultTrafficTreatment.builder().extension(buildExtension(deviceService, node.tunBridge(), localNode.dataIp().getIp4Address()), node.tunBridge()).setTunnelId(Long.valueOf(k8sNetwork.segmentId())).setOutput(portNum).build();
FlowRule remoteFlowRule = DefaultFlowRule.builder().forDevice(node.tunBridge()).withSelector(sBuilder.build()).withTreatment(treatmentToRemote).withPriority(PRIORITY_CIDR_RULE).fromApp(appId).makePermanent().forTable(TUN_ENTRY_TABLE).build();
applyRule(remoteFlowRule, true);
}
FlowRule flowRule = DefaultFlowRule.builder().forDevice(node.intgBridge()).withSelector(sBuilder.build()).withTreatment(tBuilder.build()).withPriority(PRIORITY_CIDR_RULE).fromApp(appId).makePermanent().forTable(ROUTING_TABLE).build();
applyRule(flowRule, true);
}
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class InternalConnectivityCommand method doExecute.
@Override
protected void doExecute() throws Exception {
ConnectPoint inputConnectPoint = ConnectPoint.deviceConnectPoint(input);
ConnectPoint outputConnectPoint = ConnectPoint.deviceConnectPoint(output);
DeviceService deviceService = get(DeviceService.class);
DeviceId inputDeviceId = inputConnectPoint.deviceId();
DeviceId outputDeviceId = outputConnectPoint.deviceId();
PortNumber inputPortNumber = inputConnectPoint.port();
PortNumber outputPortNumber = outputConnectPoint.port();
InternalConnectivity internalConnectivityBehaviour;
if (!inputDeviceId.equals(outputDeviceId)) {
print("[ERROR] specified connect points should belong to the same device.");
return;
}
Device device = deviceService.getDevice(inputDeviceId);
if (device != null && device.is(InternalConnectivity.class)) {
internalConnectivityBehaviour = device.as(InternalConnectivity.class);
} else {
print("[ERROR] specified device %s does not support Internal Connectivity Behaviour.", device.toString());
return;
}
if (internalConnectivityBehaviour.testConnectivity(inputPortNumber, outputPortNumber)) {
print("[CONNECTIVITY ALLOWED] device %s from input-port %s to output-port %s", device.id().toString(), inputPortNumber.toString(), outputPortNumber.toString());
} else {
print("[CONNECTIVITY NOT ALLOWED] device %s from input-port %s to output-port %s", device.id().toString(), inputPortNumber.toString(), outputPortNumber.toString());
}
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class GetFlowStatisticsCommand method doExecute.
@Override
protected void doExecute() {
DeviceService deviceService = get(DeviceService.class);
FlowStatisticService flowStatsService = get(FlowStatisticService.class);
String deviceUri = getDeviceId(devicePort);
String portUri = getPortNumber(devicePort);
DeviceId ingressDeviceId = deviceId(deviceUri);
PortNumber ingressPortNumber;
if (portUri.length() == 0) {
ingressPortNumber = null;
} else {
ingressPortNumber = portNumber(portUri);
}
Device device = deviceService.getDevice(ingressDeviceId);
if (device == null) {
error("No such device %s", ingressDeviceId.uri());
return;
}
if (ingressPortNumber != null) {
Port port = deviceService.getPort(ingressDeviceId, ingressPortNumber);
if (port == null) {
error("No such port %s on device %s", portUri, ingressDeviceId.uri());
return;
}
}
if (flowLiveType != null) {
flowLiveType = flowLiveType.toUpperCase();
}
if (instructionType != null) {
instructionType = instructionType.toUpperCase();
}
// convert String to FlowLiveType and check validity
FlowEntry.FlowLiveType inLiveType;
if (flowLiveType == null) {
inLiveType = null;
} else {
inLiveType = getFlowLiveType(flowLiveType);
if (inLiveType == null) {
error("Invalid flow live type [%s] error", flowLiveType);
return;
}
}
// convert String to InstructionType and check validity
Instruction.Type inInstructionType;
if (instructionType == null) {
inInstructionType = null;
} else {
inInstructionType = getInstructionType(instructionType);
if (inInstructionType == null) {
error("Invalid instruction type [%s] error", instructionType);
return;
}
}
if (showTopn != null) {
int topn = Integer.parseInt(showTopn);
if (topn <= 0) {
// default value
topn = 100;
} else if (topn > 1000) {
// max value
topn = 1000;
}
// print show topn head line with type
print("deviceId=%s, show TOPN=%s flows, liveType=%s, instruction type=%s", deviceUri, Integer.toString(topn), flowLiveType == null ? "ALL" : flowLiveType, instructionType == null ? "ALL" : instructionType);
if (ingressPortNumber == null) {
Map<ConnectPoint, List<FlowEntryWithLoad>> typedFlowLoadMap = flowStatsService.loadTopnByType(device, inLiveType, inInstructionType, topn);
// print all ports topn flows load for a given device
for (ConnectPoint cp : typedFlowLoadMap.keySet()) {
printPortFlowsLoad(cp, typedFlowLoadMap.get(cp));
}
} else {
List<FlowEntryWithLoad> typedFlowLoad = flowStatsService.loadTopnByType(device, ingressPortNumber, inLiveType, inInstructionType, topn);
// print device/port topn flows load
ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber);
printPortFlowsLoad(cp, typedFlowLoad);
}
} else if (showAll) {
// is true?
// print show all head line with type
print("deviceId=%s, show ALL flows, liveType=%s, instruction type=%s", deviceUri, flowLiveType == null ? "ALL" : flowLiveType, instructionType == null ? "ALL" : instructionType);
if (ingressPortNumber == null) {
Map<ConnectPoint, List<FlowEntryWithLoad>> typedFlowLoadMap = flowStatsService.loadAllByType(device, inLiveType, inInstructionType);
// print all ports all flows load for a given device
for (ConnectPoint cp : typedFlowLoadMap.keySet()) {
printPortFlowsLoad(cp, typedFlowLoadMap.get(cp));
}
} else {
List<FlowEntryWithLoad> typedFlowLoad = flowStatsService.loadAllByType(device, ingressPortNumber, inLiveType, inInstructionType);
// print device/port all flows load
ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber);
printPortFlowsLoad(cp, typedFlowLoad);
}
} else {
// if (showSummary == true) //always is true
// print show summary head line
print("deviceId=%s, show SUMMARY flows", deviceUri);
if (ingressPortNumber == null) {
Map<ConnectPoint, SummaryFlowEntryWithLoad> summaryFlowLoadMap = flowStatsService.loadSummary(device);
// print all ports flow load summary for a given device
for (ConnectPoint cp : summaryFlowLoadMap.keySet()) {
printPortSummaryLoad(cp, summaryFlowLoadMap.get(cp));
}
} else {
SummaryFlowEntryWithLoad summaryFlowLoad = flowStatsService.loadSummary(device, ingressPortNumber);
// print device/port flow load summary
ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber);
printPortSummaryLoad(cp, summaryFlowLoad);
}
}
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class GetInternalConnectivityOutputPortsCommand method doExecute.
@Override
protected void doExecute() throws Exception {
ConnectPoint inputConnectPoint = ConnectPoint.deviceConnectPoint(input);
DeviceService deviceService = get(DeviceService.class);
DeviceId inputDeviceId = inputConnectPoint.deviceId();
PortNumber inputPortNumber = inputConnectPoint.port();
InternalConnectivity internalConnectivityBehaviour;
Device device = deviceService.getDevice(inputDeviceId);
if (device != null && device.is(InternalConnectivity.class)) {
internalConnectivityBehaviour = device.as(InternalConnectivity.class);
} else {
print("[ERROR] specified device %s does not support Internal Connectivity Behaviour.", device.toString());
return;
}
Set<PortNumber> outputPorts = internalConnectivityBehaviour.getOutputPorts(inputPortNumber);
List<PortNumber> outputPortsList = outputPorts.stream().sorted((a, b) -> (int) (a.toLong() - b.toLong())).collect(Collectors.toList());
if (outputPorts.isEmpty()) {
print("[POSSIBLE OUTPUT PORTS] None!");
} else {
print("[POSSIBLE OUTPUT PORTS] " + outputPortsList.toString());
}
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class GetStatisticsCommand method doExecute.
@Override
protected void doExecute() {
StatisticService service = get(StatisticService.class);
DeviceId ingressDeviceId = deviceId(getDeviceId(connectPoint));
PortNumber ingressPortNumber = portNumber(getPortNumber(connectPoint));
ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber);
Load load = service.load(cp);
print("Load on %s -> %s", cp, load);
}
Aggregations