use of org.projectfloodlight.openflow.types.U64 in project open-kilda by telstra.
the class MetadataBaseTest method testFieldsIntersection.
protected void testFieldsIntersection(BitField[] fields) {
for (int leftIdx = 0; leftIdx < fields.length; leftIdx++) {
U64 leftField = MetadataBase.setField(U64.ZERO, -1L, fields[leftIdx]);
for (int rightIdx = 0; rightIdx < fields.length; rightIdx++) {
if (leftIdx == rightIdx) {
continue;
}
U64 rightField = MetadataBase.setField(U64.ZERO, -1, fields[rightIdx]);
Assert.assertEquals(String.format("Detect bit-fields collision between %s and %s", leftField, rightField), U64.ZERO, leftField.and(rightField));
}
}
}
use of org.projectfloodlight.openflow.types.U64 in project open-kilda by telstra.
the class SwitchManager method deleteAllNonDefaultRules.
@Override
public List<Long> deleteAllNonDefaultRules(final DatapathId dpid) throws SwitchOperationException {
List<OFFlowStatsEntry> flowStatsBefore = dumpFlowTable(dpid);
IOFSwitch sw = lookupSwitch(dpid);
OFFactory ofFactory = sw.getOFFactory();
Set<Long> removedRules = new HashSet<>();
for (OFFlowStatsEntry flowStatsEntry : flowStatsBefore) {
long flowCookie = flowStatsEntry.getCookie().getValue();
if (!isDefaultRule(flowCookie)) {
OFFlowDelete flowDelete = ofFactory.buildFlowDelete().setCookie(U64.of(flowCookie)).setCookieMask(U64.NO_MASK).setTableId(TableId.ALL).build();
pushFlow(sw, "--DeleteFlow--", flowDelete);
logger.info("Rule with cookie {} is to be removed from switch {}.", flowCookie, dpid);
removedRules.add(flowCookie);
}
}
// Wait for OFFlowDelete to be processed.
sendBarrierRequest(sw);
List<OFFlowStatsEntry> flowStatsAfter = dumpFlowTable(dpid);
Set<Long> cookiesAfter = flowStatsAfter.stream().map(entry -> entry.getCookie().getValue()).collect(Collectors.toSet());
flowStatsBefore.stream().map(entry -> entry.getCookie().getValue()).filter(cookie -> !cookiesAfter.contains(cookie)).filter(cookie -> !removedRules.contains(cookie)).forEach(cookie -> {
logger.warn("Rule with cookie {} has been removed although not requested. Switch {}.", cookie, dpid);
removedRules.add(cookie);
});
cookiesAfter.stream().filter(removedRules::contains).forEach(cookie -> {
logger.warn("Rule with cookie {} was requested to be removed, but it still remains. Switch {}.", cookie, dpid);
removedRules.remove(cookie);
});
return new ArrayList<>(removedRules);
}
use of org.projectfloodlight.openflow.types.U64 in project open-kilda by telstra.
the class OfInput method packetInCookie.
/**
* Extract cookie value from OFPacketIn message.
*/
public U64 packetInCookie() {
if (getType() != OFType.PACKET_IN) {
throw new IllegalStateException(String.format("%s.packetInCookie() is applicable only for %s (called for %s)", getClass().getName(), OFType.PACKET_IN, getType()));
}
OFPacketIn packet = (OFPacketIn) message;
final U64 cookie;
try {
cookie = packet.getCookie();
} catch (UnsupportedOperationException e) {
return null;
}
return cookie;
}
use of org.projectfloodlight.openflow.types.U64 in project open-kilda by telstra.
the class ConnectedDevicesService method handlePacketIn.
private void handlePacketIn(OfInput input) {
U64 rawCookie = input.packetInCookie();
if (rawCookie == null) {
return;
}
ServiceCookie cookie = new ServiceCookie(rawCookie.getValue());
SwitchId switchId = new SwitchId(input.getDpId().getLong());
final ServiceCookieTag serviceTag = cookie.getServiceTag();
if (lldpServiceTags.contains(serviceTag)) {
logger.debug("Receive connected device LLDP packet from {} OF-xid:{}, cookie: {}", input.getDpId(), input.getMessage().getXid(), cookie);
handleSwitchLldp(input, switchId, cookie.getValue());
} else if (arpServiceTags.contains(serviceTag)) {
logger.debug("Receive connected device ARP packet from {} OF-xid:{}, cookie: {}", input.getDpId(), input.getMessage().getXid(), cookie);
handleArp(input, switchId, cookie.getValue());
}
}
use of org.projectfloodlight.openflow.types.U64 in project open-kilda by telstra.
the class OfMatchConverter method getMasked.
private FieldMatch getMasked(Match match, MatchField<?> field) {
FieldMatchBuilder builder = FieldMatch.builder();
switch(field.id) {
case ETH_SRC:
Masked<MacAddress> ethSrcMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.ETH_SRC);
builder.field(Field.ETH_SRC);
builder.value(ethSrcMasked.getValue().getLong());
builder.mask(ethSrcMasked.getMask().getLong());
break;
case ETH_DST:
Masked<MacAddress> ethDstMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.ETH_DST);
builder.field(Field.ETH_DST);
builder.value(ethDstMasked.getValue().getLong());
builder.mask(ethDstMasked.getMask().getLong());
break;
case ETH_TYPE:
Masked<EthType> ethTypeMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.ETH_TYPE);
builder.field(Field.ETH_TYPE);
builder.value(ethTypeMasked.getValue().getValue());
builder.mask((long) ethTypeMasked.getMask().getValue());
break;
case IP_PROTO:
Masked<IpProtocol> ipProtocolMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.IP_PROTO);
builder.field(Field.IP_PROTO);
builder.value(ipProtocolMasked.getValue().getIpProtocolNumber());
builder.mask((long) ipProtocolMasked.getMask().getIpProtocolNumber());
break;
case UDP_SRC:
Masked<TransportPort> udpSrcMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.UDP_SRC);
builder.field(Field.UDP_SRC);
builder.value(udpSrcMasked.getValue().getPort());
builder.mask((long) udpSrcMasked.getMask().getPort());
break;
case UDP_DST:
Masked<TransportPort> udpDstMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.UDP_DST);
builder.field(Field.UDP_DST);
builder.value(udpDstMasked.getValue().getPort());
builder.mask((long) udpDstMasked.getMask().getPort());
break;
case METADATA:
Masked<OFMetadata> metadataMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.METADATA);
builder.field(Field.METADATA);
builder.value(metadataMasked.getValue().getValue().getValue());
builder.mask(metadataMasked.getMask().getValue().getValue());
break;
case IN_PORT:
Masked<OFPort> inPortMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.IN_PORT);
builder.field(Field.IN_PORT);
builder.value(inPortMasked.getValue().getPortNumber());
builder.mask((long) inPortMasked.getMask().getPortNumber());
break;
case VLAN_VID:
Masked<OFVlanVidMatch> vlanVidMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.VLAN_VID);
builder.field(Field.VLAN_VID);
builder.value(vlanVidMasked.getValue().getVlan());
builder.mask((long) vlanVidMasked.getMask().getVlan());
break;
case TUNNEL_ID:
Masked<U64> tunnelIdMasked = match.getMaskedWithoutPrerequisitesCheck(MatchField.TUNNEL_ID);
builder.field(Field.NOVIFLOW_TUNNEL_ID);
builder.value(tunnelIdMasked.getValue().getValue());
builder.mask(tunnelIdMasked.getMask().getValue());
break;
case KILDA_VXLAN_VNI:
Masked<U32> masked = match.getMaskedWithoutPrerequisitesCheck(MatchField.KILDA_VXLAN_VNI);
builder.field(Field.OVS_VXLAN_VNI);
builder.value(masked.getValue().getValue());
builder.mask(masked.getMask().getValue());
break;
default:
throw new IllegalArgumentException(String.format("Unexpected match field id=%s, for class=%s of a match %s", field.id, field.getClass().getName(), match));
}
return builder.build();
}
Aggregations