private VlanId getVlan(JsonNode node) { VlanId vlan = VlanId.NONE; if (!node.path(VLAN).isMissingNode()) { vlan = VlanId.vlanId(node.path(VLAN).asText()); } return vlan; }
@Override public Set<Interface> getInterfacesByVlan(VlanId vlan) { return interfaces.values() .stream() .flatMap(Collection::stream) .filter(intf -> intf.vlan().equals(vlan)) .collect(collectingAndThen(toSet(), ImmutableSet::copyOf)); }
@Override public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { final VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) criterion; return root.put(CriterionCodec.VLAN_ID, vlanIdCriterion.vlanId().toShort()); } }
/** * Creates a VLAN identifier Object using the supplied VLAN identifier. * * @param value VLAN identifier expressed as string * @return VLAN identifier */ public static VlanId vlanId(String value) { if (value.equals(STRING_NONE) || value.equals(STRING_NUMERIC_NONE)) { return new VlanId(); } if (value.equals(STRING_ANY)) { return new VlanId(ANY_VALUE); } try { return VlanId.vlanId(Short.parseShort(value)); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } }
if (!intf.vlan().equals(VlanId.NONE)) { formatStringBuilder.append(VLAN_FORMAT); formatStringBuilder.append(intf.vlan().toString()); if (!intf.vlanUntagged().equals(VlanId.NONE)) { formatStringBuilder.append(VLAN_UNTAGGED); formatStringBuilder.append(intf.vlanUntagged().toString()); if (!intf.vlanNative().equals(VlanId.NONE)) { formatStringBuilder.append(VLAN_NATIVE); formatStringBuilder.append(intf.vlanNative().toString());
private int createPeerGroup(MacAddress srcMac, MacAddress dstMac, VlanId vlanId, DeviceId deviceId, PortNumber port) { int nextId = flowObjectiveService.allocateNextId(); NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder() .withId(nextId) .withType(NextObjective.Type.SIMPLE) .fromApp(appId); TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder(); ttBuilder.setEthSrc(srcMac); ttBuilder.setEthDst(dstMac); ttBuilder.setOutput(port); nextObjBuilder.addTreatment(ttBuilder.build()); TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(); VlanId matchVlanId = (vlanId.equals(VlanId.NONE)) ? VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN) : vlanId; metabuilder.matchVlanId(matchVlanId); nextObjBuilder.withMeta(metabuilder.build()); flowObjectiveService.next(deviceId, nextObjBuilder.add()); return nextId; }
@Override public void forward(NeighbourMessageContext context, Interface outIntf) { Ethernet packetOut = context.packet().duplicate(); if (outIntf.vlan().equals(VlanId.NONE)) { // The egress interface has no VLAN Id. Send out an untagged // packet packetOut.setVlanID(Ethernet.VLAN_UNTAGGED); } else { // The egress interface has a VLAN set. Send out a tagged packet packetOut.setVlanID(outIntf.vlan().toShort()); } sendTo(packetOut, outIntf.connectPoint()); }
/** * Combines connect point with vlan id with separator ':' as circuit id. * e.g. of:0000000000000204/1:100 * * @return serialized circuit id for connect point and vlan ID */ public byte[] serialize() { return String .format(CIRCUIT_ID_FORMAT, connectPoint, vlanId.toString()) .getBytes(StandardCharsets.US_ASCII); }
@Override public ObjectNode encode(OfdpaMatchVlanVid vlanId, CodecContext context) { checkNotNull(vlanId, "Vlan ID cannot be null"); ObjectNode root = context.mapper().createObjectNode() .put(VLAN_ID, vlanId.vlanId().id()); return root; }
private void createMcastFilteringObjective(boolean install, Interface intf) { VlanId assignedVlan = (egressVlan().equals(VlanId.NONE)) ? VlanId.vlanId(ASSIGNED_VLAN) : egressVlan(); FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); // first add filter for the interface fob.withKey(Criteria.matchInPort(intf.connectPoint().port())) .addCondition(Criteria.matchEthDstMasked(MacAddress.IPV4_MULTICAST, MacAddress.IPV4_MULTICAST_MASK)) .addCondition(Criteria.matchVlanId(ingressVlan())); fob.withPriority(PRIORITY_OFFSET); TrafficTreatment tt = DefaultTrafficTreatment.builder() .pushVlan().setVlanId(assignedVlan).build(); fob.withMeta(tt); fob.permit().fromApp(routerAppId); sendFilteringObjective(install, fob, intf); }
@Override public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) { ExtensionSelectorType type = extensionSelector.type(); if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) { VlanId vlanId = ((OfdpaMatchVlanVid) extensionSelector).vlanId(); // Special VLAN 0x0000/0x1FFF required by OFDPA if (vlanId.equals(VlanId.NONE)) { OFVlanVidMatch vid = OFVlanVidMatch.ofRawVid((short) 0x0000); OFVlanVidMatch mask = OFVlanVidMatch.ofRawVid((short) 0x1FFF); return factory.oxms().vlanVidMasked(vid, mask); // Normal case } else if (vlanId.equals(VlanId.ANY)) { return factory.oxms().vlanVidMasked(OFVlanVidMatch.PRESENT, OFVlanVidMatch.PRESENT); } else { return factory.oxms().vlanVid(OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vlanId.toShort()))); } } throw new UnsupportedOperationException( "Unexpected ExtensionSelector: " + extensionSelector.toString()); }
private void printInterface(DeviceInterfaceDescription intf) { StringBuilder formatStringBuilder = new StringBuilder(FORMAT); if (intf.mode().equals(DeviceInterfaceDescription.Mode.ACCESS)) { formatStringBuilder.append(MODE_FORMAT) .append(ACCESS_MODE) .append(VLAN_FORMAT); formatStringBuilder.append(intf.vlans().get(0).toString()); } else if (intf.mode().equals(DeviceInterfaceDescription.Mode.TRUNK)) { formatStringBuilder.append(MODE_FORMAT) .append(TRUNK_MODE) .append(VLAN_FORMAT); for (int i = 0; i < intf.vlans().size(); i++) { formatStringBuilder.append(intf.vlans().get(i)); if (i != intf.vlans().size() - 1) { formatStringBuilder.append(","); } } } if (intf.isRateLimited()) { formatStringBuilder.append(LIMIT_FORMAT); formatStringBuilder.append(intf.rateLimit()); formatStringBuilder.append(PERCENT); } print(formatStringBuilder.toString(), intf.name()); } }
@Override public ObjectNode encode(OfdpaSetVlanVid vlanId, CodecContext context) { checkNotNull(vlanId, "Vlan ID cannot be null"); ObjectNode root = context.mapper().createObjectNode() .put(VLAN_ID, vlanId.vlanId().id()); return root; }
private static Set<VlanId> getEntireVlans() { return IntStream.range(0, MAX_VLAN_ID) .filter(x -> !EXCLUDED.contains(x)) .mapToObj(x -> VlanId.vlanId((short) x)) .collect(GuavaCollectors.toImmutableSet()); }
private void createFilteringObjective(boolean install, Interface intf) { VlanId assignedVlan = (egressVlan().equals(VlanId.NONE)) ? VlanId.vlanId(ASSIGNED_VLAN) : egressVlan(); FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); // first add filter for the interface fob.withKey(Criteria.matchInPort(intf.connectPoint().port())) .addCondition(Criteria.matchEthDst(intf.mac())) .addCondition(Criteria.matchVlanId(intf.vlan())); fob.withPriority(PRIORITY_OFFSET); if (intf.vlan() == VlanId.NONE) { TrafficTreatment tt = DefaultTrafficTreatment.builder() .pushVlan().setVlanId(assignedVlan).build(); fob.withMeta(tt); } fob.permit().fromApp(routerAppId); sendFilteringObjective(install, fob, intf); if (controlPlaneConnectPoint != null) { // then add the same mac/vlan filters for control-plane connect point fob.withKey(Criteria.matchInPort(controlPlaneConnectPoint.port())); sendFilteringObjective(install, fob, intf); } }
(egressVlan != null && !assignedVlan.equals(egressVlan)) ? egressVlan : assignedVlan; int l2gk = l2InterfaceGroupKey(deviceId, l2InterfaceGroupVlan, portNum.toLong()); final GroupKey l2InterfaceGroupKey = new DefaultGroupKey(Ofdpa2Pipeline.appKryo.serialize(l2gk)); int l2InterfaceGroupId = L2_INTERFACE_TYPE | (l2InterfaceGroupVlan.toShort() << 16) | (int) portNum.toLong(); GroupBucket l2InterfaceGroupBucket =
@Override public Set<Host> getHosts(VlanId vlanId) { Set<Host> vlanset = new HashSet<>(); for (Host h : hosts.values()) { if (h.vlan().equals(vlanId)) { vlanset.add(h); } } return vlanset; }
@Override public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { final VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) criterion; return root.put(CriterionCodec.INNER_VLAN_ID, vlanIdCriterion.vlanId().toShort()); } }
/** * Adds a BGP speaker to the configuration. * * @param speaker the BGP speaker configuration entry */ public void addSpeaker(BgpSpeakerConfig speaker) { // Create the new speaker node and set the parameters ObjectNode speakerNode = JsonNodeFactory.instance.objectNode(); speakerNode.put(NAME, speaker.name().get()); speakerNode.put(VLAN, speaker.vlan().toString()); speakerNode.put(CONNECT_POINT, speaker.connectPoint().elementId().toString() + "/" + speaker.connectPoint().port().toString()); ArrayNode peersNode = speakerNode.putArray(PEERS); for (IpAddress peerAddress: speaker.peers()) { peersNode.add(peerAddress.toString()); } // Add the new BGP speaker to the existing node array ArrayNode speakersArray = bgpSpeakers().isEmpty() ? initBgpSpeakersConfiguration() : (ArrayNode) object.get(SPEAKERS); speakersArray.add(speakerNode); }
.setDestinationMACAddress(destinationMac) .setSourceMACAddress(sourceMac); ethernet.setVlanID(vlan.id());