use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class DefaultCheckLoop method updatePktInportPerHop.
private PortCriterion updatePktInportPerHop(TsLoopPacket oldPkt, ConnectPoint dstPoint) {
PortCriterion inPort = oldPkt.getInport();
PortCriterion oldInPort = null != inPort ? (PortCriterion) matchInPort(inPort.port()) : null;
// TODO - check - if it really copies this object
oldPkt.setHeader(matchInPort(dstPoint.port()));
return oldInPort;
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class StatsFlowRuleManager method getUnderlayFlowInfos.
@Override
public Set<FlowInfo> getUnderlayFlowInfos() {
Set<FlowInfo> flowInfos = Sets.newConcurrentHashSet();
for (Device device : getUnderlayDevices()) {
if (!isEdgeSwitch(device.id())) {
continue;
}
for (FlowEntry entry : flowRuleService.getFlowEntries(device.id())) {
FlowInfo.Builder fBuilder = new DefaultFlowInfo.DefaultBuilder();
TrafficSelector selector = entry.selector();
Criterion inPort = selector.getCriterion(Criterion.Type.IN_PORT);
Criterion dstIpCriterion = selector.getCriterion(Criterion.Type.IPV4_DST);
if (inPort != null && dstIpCriterion != null) {
IpAddress srcIp = getIpAddress(device, (PortCriterion) inPort);
IpAddress dstIp = ((IPCriterion) dstIpCriterion).ip().address();
if (srcIp == null) {
continue;
}
fBuilder.withFlowType(FLOW_TYPE_SONA).withSrcIp(IpPrefix.valueOf(srcIp, ARBITRARY_LENGTH)).withDstIp(IpPrefix.valueOf(dstIp, ARBITRARY_LENGTH)).withSrcMac(getMacAddress(srcIp)).withDstMac(getMacAddress(dstIp)).withInputInterfaceId(getInterfaceId(srcIp)).withOutputInterfaceId(getInterfaceId(dstIp)).withDeviceId(entry.deviceId());
StatsInfo.Builder sBuilder = new DefaultStatsInfo.DefaultBuilder();
sBuilder.withStartupTime(System.currentTimeMillis()).withFstPktArrTime(System.currentTimeMillis()).withLstPktOffset((int) (REFRESH_INTERVAL * MILLISECONDS)).withCurrAccPkts((int) entry.packets()).withCurrAccBytes(entry.bytes()).withErrorPkts((short) 0).withDropPkts((short) 0);
fBuilder.withStatsInfo(sBuilder.build());
FlowInfo flowInfo = mergeFlowInfo(fBuilder.build(), fBuilder, sBuilder);
flowInfos.add(flowInfo);
}
}
}
return flowInfos;
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class ChannelData method fromFlow.
/**
* Returns a ChannelData representation from a flow rule. The rule must contain
* a Criterion.Type.IN_PORT selector, Criterion.Type.OCH_SIGID selector, and
* Instruction.Type.OUTPUT instruction.
*
* @param rule the flow rule representing the connection
* @return ChannelData representation of the connection
*/
public static ChannelData fromFlow(FlowRule rule) {
checkNotNull(rule);
Criterion in = rule.selector().getCriterion(Criterion.Type.IN_PORT);
checkNotNull(in);
PortNumber inPort = ((PortCriterion) in).port();
Criterion och = rule.selector().getCriterion(Criterion.Type.OCH_SIGID);
OchSignal ochSignal = och == null ? null : ((OchSignalCriterion) och).lambda();
PortNumber outPort = null;
List<Instruction> instructions = rule.treatment().allInstructions();
for (Instruction ins : instructions) {
if (ins.type() == Instruction.Type.OUTPUT) {
outPort = ((Instructions.OutputInstruction) ins).port();
}
}
checkNotNull(outPort);
return new ChannelData(inPort, outPort, ochSignal);
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class RoadmCrossConnectCommand method dropRule.
/**
* This function drops XC installed on the device, which is matching parsed criteria.
* Takes as an input "global" parameters (passed by user through the console).
* @return - returns number of the rules that were dropped.
*/
protected FlowId dropRule() {
// Preparing parameters
DeviceId device = DeviceId.deviceId(deviceId);
PortNumber inPort = PortNumber.portNumber(srcPort);
PortNumber outPort = PortNumber.portNumber(dstPort);
// Creating some variables
OchSignal ochSignal = null;
PortNumber inputPortNumber = null;
PortNumber outputPortNumber = null;
// Main idea: Go over all flow rules (read out from the storage) of current device and
// filter them based on input and output port with respect to OchSignal
FlowRuleService fr = AbstractShellCommand.get(FlowRuleService.class);
Iterable<FlowEntry> flowRules = fr.getFlowEntries(device);
FlowId flowId = null;
OchSignal referenceSignal = createOchSignal(freq, sw, gridType, channelSpacing);
for (FlowEntry flowRule : flowRules) {
// Taken from FlowRuleParser
for (Criterion c : flowRule.selector().criteria()) {
if (c instanceof OchSignalCriterion) {
ochSignal = ((OchSignalCriterion) c).lambda();
}
if (c instanceof PortCriterion) {
// obtain input port
inputPortNumber = ((PortCriterion) c).port();
}
}
for (Instruction i : flowRule.treatment().immediate()) {
if (i instanceof L0ModificationInstruction.ModOchSignalInstruction) {
ochSignal = ((L0ModificationInstruction.ModOchSignalInstruction) i).lambda();
}
if (i instanceof Instructions.OutputInstruction) {
// obtain output port
outputPortNumber = ((Instructions.OutputInstruction) i).port();
}
}
// If we found match, then let's delete this rule
if ((ochSignal.centralFrequency().equals(referenceSignal.centralFrequency())) & (ochSignal.slotWidth().equals(referenceSignal.slotWidth())) & (inputPortNumber.equals(inPort)) & (outputPortNumber.equals(outPort))) {
flowId = flowRule.id();
RoadmService manager = AbstractShellCommand.get(RoadmService.class);
manager.removeConnection(device, flowId);
print("Dropping existing XC from the device %s", deviceId);
return flowId;
}
}
return null;
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class FlowAnalyzer method analyzeInstruction.
private boolean analyzeInstruction(Instruction i, FlowEntry flow) {
boolean pointsToLiveEntry = false;
Instructions.OutputInstruction output = (Instructions.OutputInstruction) i;
PortNumber port = output.port();
PortNumber outPort = null;
DeviceId egress = null;
boolean hasHost = false;
ConnectPoint portPt = new ConnectPoint(flow.deviceId(), port);
for (Link l : linkService.getEgressLinks(portPt)) {
if (l.dst().elementId() instanceof DeviceId) {
egress = l.dst().deviceId();
outPort = l.dst().port();
} else if (l.dst().elementId() instanceof HostId) {
// the port leads to a host: therefore it is not a dead link
pointsToLiveEntry = true;
hasHost = true;
}
}
if (!topologyService.isInfrastructure(topologyService.currentTopology(), portPt) && egress == null) {
pointsToLiveEntry = true;
hasHost = true;
}
if (hasHost) {
return pointsToLiveEntry;
}
if (egress == null) {
// the port that the flow instructions tells you to send the packet
// to doesn't exist or is a controller port
label.put(flow, "NA");
return pointsToLiveEntry;
}
Iterable<FlowEntry> dstFlowTable = flowRuleService.getFlowEntries(egress);
Set<Criterion> flowCriteria = flow.selector().criteria();
// filter the criteria in order to remove port dependency
Set<Criterion> filteredCriteria = new HashSet<>();
for (Criterion criterion : flowCriteria) {
if (!(criterion instanceof PortCriterion)) {
filteredCriteria.add(criterion);
}
}
// ensure that the in port is equal to the port that it is coming in from
filteredCriteria.add(Criteria.matchInPort(outPort));
for (FlowEntry entry : dstFlowTable) {
if (ignoredFlows.contains(entry)) {
continue;
}
if (filteredCriteria.containsAll(entry.selector().criteria())) {
dfs(entry);
if (!"Black Hole".equals(label.get(entry))) {
// this entry is "live" i.e not a black hole
pointsToLiveEntry = true;
}
}
}
return pointsToLiveEntry;
}
Aggregations