@Override public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { final EthTypeCriterion ethTypeCriterion = (EthTypeCriterion) criterion; return root.put(CriterionCodec.ETH_TYPE, "0x" + Integer.toHexString(ethTypeCriterion.ethType().toShort() & 0xffff)); } }
/** * Constructs a new ethertype. * * @param ethType The actual ethertype * @param type it's textual representation * @param deserializer a parser for this ethertype */ EtherType(int ethType, String type, Deserializer<?> deserializer) { this.etherType = new EthType(ethType); this.type = type; this.deserializer = deserializer; }
public String toString() { EtherType ethType = lookup(this.etherType); return (ethType == null ? String.format("0x%04x", etherType) : ethType.toString()); }
final L2ModificationInstruction.ModVlanHeaderInstruction pushVlanInstruction = (L2ModificationInstruction.ModVlanHeaderInstruction) l2Instruction; result.put(InstructionCodec.ETHERNET_TYPE, pushVlanInstruction.ethernetType().toString()); break; case VLAN_POP: (L2ModificationInstruction.ModMplsHeaderInstruction) l2Instruction; result.put(InstructionCodec.ETHERNET_TYPE, pushHeaderInstructions.ethernetType().toShort()); break; case TUNNEL_ID: (L2ModificationInstruction.ModMplsHeaderInstruction) l2Instruction; result.put(InstructionCodec.ETHERNET_TYPE, toHexWithPrefix(popHeaderInstruction.ethernetType().toShort())); break; case DEC_MPLS_TTL:
@Override public ObjectNode encode(Host host, CodecContext context) { checkNotNull(host, "Host cannot be null"); final JsonCodec<HostLocation> locationCodec = context.codec(HostLocation.class); final ObjectNode result = context.mapper().createObjectNode() .put("id", host.id().toString()) .put("mac", host.mac().toString()) .put("vlan", host.vlan().toString()) .put("innerVlan", host.innerVlan().toString()) .put("outerTpid", host.tpid().toString()) .put("configured", host.configured()); final ArrayNode jsonIpAddresses = result.putArray("ipAddresses"); for (final IpAddress ipAddress : host.ipAddresses()) { jsonIpAddresses.add(ipAddress.toString()); } result.set("ipAddresses", jsonIpAddresses); final ArrayNode jsonLocations = result.putArray("locations"); for (final HostLocation location : host.locations()) { jsonLocations.add(locationCodec.encode(location, context)); } result.set("locations", jsonLocations); return annotate(result, host, context); }
/** * Prints information about a host. * * @param host end-station host */ protected void printHost(Host host) { if (shortOnly) { print(FMT_SHORT, host.id(), host.mac(), host.locations(), host.vlan(), host.ipAddresses()); } else { print(FMT, host.id(), host.mac(), host.locations(), host.vlan(), host.ipAddresses(), annotations(host.annotations()), host.innerVlan(), host.tpid().toString(), host.providerId().scheme(), host.providerId().id(), host.configured()); } } }
private boolean isSupportedEthTypeObjective(ForwardingObjective fwd) { TrafficSelector selector = fwd.selector(); EthTypeCriterion ethType = (EthTypeCriterion) selector .getCriterion(Criterion.Type.ETH_TYPE); if ((ethType == null) || ((ethType.ethType().toShort() != Ethernet.TYPE_IPV4) && (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST))) { return false; } return true; }
/** * Returns Ethernet type. * * @return ethernet type * @throws IllegalArgumentException if the JSON is invalid */ private EthType getEthType() { String ethTypeStr = nullIsIllegal(json.get(InstructionCodec.ETHERNET_TYPE), InstructionCodec.ETHERNET_TYPE + InstructionCodec.MISSING_MEMBER_MESSAGE).asText(); Matcher matcher = ETHTYPE_PATTERN.matcher(ethTypeStr); if (!matcher.matches()) { throw new IllegalArgumentException("ETHERNET_TYPE must be a four digit hex string starting with 0x"); } short ethernetType = (short) Integer.parseInt(matcher.group(1), 16); return new EthType(ethernetType); }
public static EtherType lookup(short etherType) { for (EtherType ethType : EtherType.values()) { if (ethType.ethType().toShort() == etherType) { return ethType; } } return UNKNOWN; }
case POP_MPLS: OFActionPopMpls popMpls = (OFActionPopMpls) act; builder.popMpls(new EthType(popMpls.getEthertype().getValue())); break; case PUSH_MPLS:
private boolean isSupportedEthTypeObjective(ForwardingObjective fwd) { TrafficSelector selector = fwd.selector(); EthTypeCriterion ethType = (EthTypeCriterion) selector .getCriterion(Criterion.Type.ETH_TYPE); return !((ethType == null) || ((ethType.ethType().toShort() != Ethernet.TYPE_IPV4) && (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST))); }
/** * Looks up the ethertype by it's numerical representation * and returns it's textual format. * * @param etherType the short value of the ethertype * @return a textual representation */ public EtherType lookup(short etherType) { for (EtherType ethType : EtherType.values()) { if (ethType.ethType().toShort() == etherType) { return ethType; } } return null; }
@Override public void init(Criterion criterion, int bitWidth) throws ByteSequenceTrimException { EthTypeCriterion c = (EthTypeCriterion) criterion; initAsExactMatch(copyFrom(c.ethType().toShort()), bitWidth); } }
if (ethType.ethType().toShort() == Ethernet.TYPE_ARP) { if (filters.isEmpty()) { pendingVersatiles.add(fwd);
private Collection<FlowRule> processVersatile(ForwardingObjective forwardingObjective) { log.debug("Processing versatile forwarding objective"); FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(forwardingObjective.selector()) .withTreatment(forwardingObjective.treatment()) .withPriority(forwardingObjective.priority()) .fromApp(forwardingObjective.appId()); if (forwardingObjective.permanent()) { ruleBuilder.makePermanent(); } else { ruleBuilder.makeTemporary(TIME_OUT); } //ARP & DHCP Rule EthTypeCriterion ethCriterion = (EthTypeCriterion) forwardingObjective.selector().getCriterion(Criterion.Type.ETH_TYPE); UdpPortCriterion udpPortCriterion = (UdpPortCriterion) forwardingObjective .selector().getCriterion(Criterion.Type.UDP_DST); if (ethCriterion != null) { if (ethCriterion.ethType().toShort() == Ethernet.TYPE_ARP || ethCriterion.ethType().toShort() == Ethernet.TYPE_LLDP) { ruleBuilder.forTable(VNI_TABLE); return Collections.singletonList(ruleBuilder.build()); } else if (udpPortCriterion != null && udpPortCriterion.udpPort().toInt() == DHCP_SERVER_PORT) { ruleBuilder.forTable(VNI_TABLE); return Collections.singletonList(ruleBuilder.build()); } } return Collections.emptySet(); }
@Override public void programArpClassifierRules(DeviceId deviceId, PortNumber inPort, IpAddress dstIp, SegmentationId actionVni, Objective.Operation type) { TrafficSelector selector = DefaultTrafficSelector.builder() .matchInPort(inPort).matchEthType(ETH_TYPE.ethType().toShort()) .matchArpTpa(Ip4Address.valueOf(dstIp.toString())).build(); TrafficTreatment treatment = DefaultTrafficTreatment.builder() .setTunnelId(Long.parseLong(actionVni.segmentationId())) .build(); ForwardingObjective.Builder objective = DefaultForwardingObjective .builder().withTreatment(treatment).withSelector(selector) .fromApp(appId).withFlag(Flag.SPECIFIC) .withPriority(ARP_CLASSIFIER_PRIORITY); if (type.equals(Objective.Operation.ADD)) { log.debug("ArpClassifierRules-->ADD"); flowObjectiveService.forward(deviceId, objective.add()); } else { log.debug("ArpClassifierRules-->REMOVE"); flowObjectiveService.forward(deviceId, objective.remove()); } }
private ForwardingObjective.Builder createPeerObjBuilder( int nextId, IpPrefix ipAddresses) { TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); sbuilder.matchEthType(EthType.EtherType.IPV4.ethType().toShort()); sbuilder.matchIPDst(ipAddresses); DefaultForwardingObjective.Builder builder = DefaultForwardingObjective.builder() .withSelector(sbuilder.build()) .fromApp(appId) .withPriority(getPriorityFromPrefix(ipAddresses)) .withFlag(ForwardingObjective.Flag.SPECIFIC); if (nextId != -1) { builder.nextStep(nextId); } return builder; }
@Override public void programArpClassifierRules(DeviceId deviceId, IpAddress dstIp, SegmentationId actionVni, Objective.Operation type) { TrafficSelector selector = DefaultTrafficSelector.builder() .matchEthType(ETH_TYPE.ethType().toShort()) .matchArpTpa(Ip4Address.valueOf(dstIp.toString())) .build(); TrafficTreatment treatment = DefaultTrafficTreatment.builder() .setTunnelId(Long.parseLong(actionVni.segmentationId())) .build(); ForwardingObjective.Builder objective = DefaultForwardingObjective .builder().withTreatment(treatment).withSelector(selector) .fromApp(appId).withFlag(Flag.SPECIFIC) .withPriority(ARP_CLASSIFIER_PRIORITY); if (type.equals(Objective.Operation.ADD)) { log.debug("ArpClassifierRules-->ADD"); flowObjectiveService.forward(deviceId, objective.add()); } else { log.debug("ArpClassifierRules-->REMOVE"); flowObjectiveService.forward(deviceId, objective.remove()); } }
EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) { fail(fwd, ObjectiveError.UNSUPPORTED); return Collections.emptySet();